Submission #38426
ソースコード
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 | #include<bits/stdc++.h> using namespace std; #define fi first #define se second void dfs( int now); void rdfs( int now, int k); typedef pair< int , int >P; int n,m; vector< int >node[10009]; vector< int >rnode[10009]; vector< int >v; vector<P>edge; bool f[10009]; int cmp[10009]; int cnt_edge_in[10009]; int cnt_edge_out[10009]; int main(){ scanf ( "%d %d" ,&n,&m); for ( int i=0;i<m;i++){ int s,t; scanf ( "%d %d" ,&s,&t); node[s].push_back(t); rnode[t].push_back(s); edge.push_back(P(s,t)); } memset (f,0, sizeof (f)); for ( int i=0;i<n;i++){ if (!f[i])dfs(i); } memset (f,0, sizeof (f)); int k=0; for ( int i=v.size()-1;i>=0;i--){ if (!f[v[i]])rdfs(v[i],k++); } for ( int i=0;i<m;i++){ int s=edge[i].fi; int t=edge[i].se; if (cmp[s]!=cmp[t]){ cnt_edge_in[cmp[t]]++; cnt_edge_out[cmp[s]]++; } } int a=0,b=0; for ( int i=0;i<k;i++){ if (!cnt_edge_in[i])a++; if (!cnt_edge_out[i])b++; } if (k==1) printf ( "%d\n" ,0); else printf ( "%d\n" ,max(a,b)); return (0); } void dfs( int now){ f[now]= true ; for ( int i=0;i<node[now].size();i++){ if (!f[node[now][i]]){ dfs(node[now][i]); } } v.push_back(now); } void rdfs( int now, int k){ f[now]= true ; cmp[now]=k; for ( int i=0;i<rnode[now].size();i++){ if (!f[rnode[now][i]]){ rdfs(rnode[now][i],k); } } } |
ステータス
項目 | データ |
---|---|
問題 | 0964 - 道路網改修 |
ユーザー名 | r1705 |
投稿日時 | 2018-07-09 18:00:16 |
言語 | C++11 |
状態 | Accepted |
得点 | 14 |
ソースコード長 | 1424 Byte |
最大実行時間 | 64 ms |
最大メモリ使用量 | 11012 KB |
セット
セット | 得点 | Cases | |
---|---|---|---|
1 | ALL | 14 / 14 | * |
テストケース
ファイル名 | 状態 | 実行時間 | メモリ使用量 | # |
---|---|---|---|---|
in1.txt | AC | 27 ms | 992 KB |
1
|
in2.txt | AC | 29 ms | 5360 KB |
1
|
in3.txt | AC | 24 ms | 7448 KB |
1
|
in4.txt | AC | 34 ms | 8308 KB |
1
|
in5.txt | AC | 27 ms | 8304 KB |
1
|
in6.txt | AC | 24 ms | 8436 KB |
1
|
in7.txt | AC | 35 ms | 9704 KB |
1
|
in8.txt | AC | 21 ms | 8732 KB |
1
|
in9.txt | AC | 44 ms | 10940 KB |
1
|
in10.txt | AC | 58 ms | 2900 KB |
1
|
in11.txt | AC | 29 ms | 2532 KB |
1
|
in12.txt | AC | 25 ms | 2804 KB |
1
|
in13.txt | AC | 19 ms | 1860 KB |
1
|
in14.txt | AC | 54 ms | 5564 KB |
1
|
in15.txt | AC | 64 ms | 6208 KB |
1
|
in16.txt | AC | 44 ms | 7284 KB |
1
|
in17.txt | AC | 53 ms | 8176 KB |
1
|
in18.txt | AC | 22 ms | 5496 KB |
1
|
in19.txt | AC | 22 ms | 5360 KB |
1
|
in20.txt | AC | 33 ms | 6636 KB |
1
|
in21.txt | AC | 20 ms | 5872 KB |
1
|
in22.txt | AC | 25 ms | 5916 KB |
1
|
in23.txt | AC | 25 ms | 5992 KB |
1
|
in24.txt | AC | 28 ms | 6080 KB |
1
|
in25.txt | AC | 23 ms | 6348 KB |
1
|
in26.txt | AC | 24 ms | 6616 KB |
1
|
in27.txt | AC | 25 ms | 7060 KB |
1
|
in28.txt | AC | 27 ms | 7908 KB |
1
|
in29.txt | AC | 47 ms | 9688 KB |
1
|
in30.txt | AC | 54 ms | 11012 KB |
1
|