結果
問題 | No.1023 Cyclic Tour |
ユーザー | SSRS |
提出日時 | 2020-04-10 22:48:00 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,834 bytes |
コンパイル時間 | 1,995 ms |
コンパイル使用メモリ | 180,220 KB |
実行使用メモリ | 25,420 KB |
最終ジャッジ日時 | 2023-10-14 03:31:47 |
合計ジャッジ時間 | 13,656 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,348 KB |
testcase_01 | WA | - |
testcase_02 | AC | 2 ms
4,348 KB |
testcase_03 | WA | - |
testcase_04 | AC | 97 ms
11,076 KB |
testcase_05 | AC | 97 ms
11,056 KB |
testcase_06 | AC | 113 ms
11,376 KB |
testcase_07 | AC | 107 ms
10,972 KB |
testcase_08 | AC | 128 ms
18,284 KB |
testcase_09 | AC | 122 ms
18,088 KB |
testcase_10 | AC | 120 ms
17,732 KB |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | AC | 115 ms
19,552 KB |
testcase_15 | WA | - |
testcase_16 | AC | 200 ms
25,036 KB |
testcase_17 | AC | 201 ms
25,420 KB |
testcase_18 | AC | 204 ms
24,608 KB |
testcase_19 | AC | 201 ms
24,316 KB |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | AC | 222 ms
16,880 KB |
testcase_26 | AC | 205 ms
13,288 KB |
testcase_27 | AC | 184 ms
11,468 KB |
testcase_28 | AC | 230 ms
23,584 KB |
testcase_29 | AC | 216 ms
24,332 KB |
testcase_30 | AC | 233 ms
23,844 KB |
testcase_31 | AC | 225 ms
22,488 KB |
testcase_32 | AC | 228 ms
23,124 KB |
testcase_33 | AC | 236 ms
23,356 KB |
testcase_34 | AC | 228 ms
18,316 KB |
testcase_35 | AC | 227 ms
16,088 KB |
testcase_36 | WA | - |
testcase_37 | AC | 221 ms
21,236 KB |
testcase_38 | AC | 219 ms
23,320 KB |
testcase_39 | WA | - |
testcase_40 | AC | 227 ms
21,232 KB |
testcase_41 | AC | 230 ms
21,080 KB |
testcase_42 | AC | 207 ms
13,804 KB |
testcase_43 | AC | 220 ms
23,584 KB |
testcase_44 | AC | 101 ms
11,228 KB |
testcase_45 | AC | 122 ms
21,972 KB |
testcase_46 | AC | 113 ms
21,760 KB |
testcase_47 | WA | - |
testcase_48 | WA | - |
testcase_49 | WA | - |
testcase_50 | WA | - |
testcase_51 | AC | 181 ms
15,240 KB |
testcase_52 | AC | 180 ms
15,060 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; int main(){ int N, M; cin >> N >> M; vector<vector<int>> E1(N), E2(N); for (int i = 0; i < M; i++){ int a, b, c; cin >> a >> b >> c; a--; b--; if (c == 1){ E1[a].push_back(b); E1[b].push_back(a); } if (c == 2){ E2[a].push_back(b); } } int gcount = 0; vector<int> G(N, -1); for (int i = 0; i < N; i++){ if (G[i] == -1){ G[i] = gcount; queue<int> Q; Q.push(i); while (!Q.empty()){ int v = Q.front(); Q.pop(); for (int w : E1[v]){ if (G[w] == -1){ G[w] = gcount; Q.push(w); } } } gcount++; } } vector<int> Vcount(gcount, 0); for (int i = 0; i < N; i++){ Vcount[G[i]]++; } vector<int> Ecount(gcount, 0); for (int i = 0; i < N; i++){ for (int j : E1[i]){ Ecount[G[i]]++; } } vector<set<int>> E3(gcount); bool self_loop = false; for (int i = 0; i < N; i++){ for (int j : E2[i]){ E3[G[i]].insert(G[j]); } } //トポロジカルソートを試みる vector<int> indeg(gcount, 0); for (int i = 0; i < gcount; i++){ for (int j : E3[i]){ indeg[j]++; } } queue<int> Q; for (int i = 0; i < gcount; i++){ if (indeg[i] == 0){ Q.push(i); } } int count = 0; while (!Q.empty()){ int v = Q.front(); Q.pop(); count++; for (int w : E3[v]){ indeg[w]--; if (indeg[w] == 0){ Q.push(w); } } } if (count != gcount){ cout << "Yes" << endl; } else { bool res = false; for (int i = 0; i < gcount; i++){ if (Ecount[i] >= Vcount[i]){ res = true; } } if (res){ cout << "Yes" << endl; } else { cout << "No" << endl; } } }