Submission #41991
ソースコード
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 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #include <vector> using namespace std; #define rep(i,n) for(int i=0; i<(n); ++i) #define outl(x) cout<< (x) << '\n' using pii = pair< int , int >; using ll = long long ; template < class A, class B> inline bool chmax(A &a, B b){ return b>a ? a=b,1 : 0;} template < class A, class B> inline bool chmin(A &a, B b){ return b<a ? a=b,1 : 0;} static constexpr int INF = 0x3f3f3f3f; static constexpr int LIM = 10010; int V, E; vector< int > G[LIM], rG[LIM]; vector< int > vs; bool used[LIM]; int cmp[LIM]; void addEdge( int from, int to) { G[from].push_back(to); rG[to].push_back(from); } void dfs( int u) { used[u] = true ; for ( int e: G[u]) { if (!used[e]) dfs(e); } vs.push_back(u); } void rdfs( int u, int k) { used[u] = true ; cmp[u] = k; for ( int e: rG[u]) { if (!used[e]) rdfs(e, k); } } int scc() { memset (used, 0, sizeof (used)); vs.clear(); rep(i, V) { if (!used[i]) dfs(i); } memset (used, 0, sizeof (used)); int k = 0; for_each(vs.rbegin(), vs.rend(), [&k]( int e){ if (!used[e]) rdfs(e, k++);} ); return k; } int indeg[LIM], outdeg[LIM]; int main() { cin.tie(0), ios::sync_with_stdio( false ); cin >> V >> E; rep(i, E) { int s, t; cin >> s >> t; addEdge(s, t); } int K = scc(); rep(src, V) { for ( int e: G[src]) { if (cmp[src] == cmp[e]) continue ; ++indeg[cmp[e]]; ++outdeg[cmp[src]]; } } if (K == 1) { outl(0); } else { outl(max( count(indeg, indeg+K, 0), count(outdeg, outdeg+K, 0) )); } return 0; } |
ステータス
項目 | データ |
---|---|
問題 | 0964 - 道路網改修 |
ユーザー名 | Arumakan_ei1727 |
投稿日時 | 2018-08-28 02:12:36 |
言語 | C++14 |
状態 | Accepted |
得点 | 14 |
ソースコード長 | 1866 Byte |
最大実行時間 | 48 ms |
最大メモリ使用量 | 3260 KB |
セット
セット | 得点 | Cases | |
---|---|---|---|
1 | ALL | 14 / 14 | * |
テストケース
ファイル名 | 状態 | 実行時間 | メモリ使用量 | # |
---|---|---|---|---|
in1.txt | AC | 37 ms | 992 KB |
1
|
in2.txt | AC | 20 ms | 1072 KB |
1
|
in3.txt | AC | 21 ms | 1120 KB |
1
|
in4.txt | AC | 19 ms | 960 KB |
1
|
in5.txt | AC | 28 ms | 1068 KB |
1
|
in6.txt | AC | 25 ms | 1184 KB |
1
|
in7.txt | AC | 20 ms | 2440 KB |
1
|
in8.txt | AC | 18 ms | 1380 KB |
1
|
in9.txt | AC | 35 ms | 2828 KB |
1
|
in10.txt | AC | 33 ms | 2128 KB |
1
|
in11.txt | AC | 26 ms | 1852 KB |
1
|
in12.txt | AC | 17 ms | 2344 KB |
1
|
in13.txt | AC | 18 ms | 1096 KB |
1
|
in14.txt | AC | 43 ms | 3260 KB |
1
|
in15.txt | AC | 39 ms | 2896 KB |
1
|
in16.txt | AC | 48 ms | 3228 KB |
1
|
in17.txt | AC | 41 ms | 3132 KB |
1
|
in18.txt | AC | 18 ms | 1104 KB |
1
|
in19.txt | AC | 24 ms | 1088 KB |
1
|
in20.txt | AC | 26 ms | 1824 KB |
1
|
in21.txt | AC | 23 ms | 1164 KB |
1
|
in22.txt | AC | 22 ms | 1192 KB |
1
|
in23.txt | AC | 23 ms | 1396 KB |
1
|
in24.txt | AC | 17 ms | 1248 KB |
1
|
in25.txt | AC | 24 ms | 1404 KB |
1
|
in26.txt | AC | 24 ms | 1472 KB |
1
|
in27.txt | AC | 30 ms | 1708 KB |
1
|
in28.txt | AC | 29 ms | 2144 KB |
1
|
in29.txt | AC | 32 ms | 2736 KB |
1
|
in30.txt | AC | 35 ms | 3152 KB |
1
|