結果
問題 | No.1023 Cyclic Tour |
ユーザー | hiroaki0615 |
提出日時 | 2020-04-10 23:10:16 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,310 bytes |
コンパイル時間 | 1,071 ms |
コンパイル使用メモリ | 95,692 KB |
実行使用メモリ | 31,360 KB |
最終ジャッジ日時 | 2024-09-16 00:02:53 |
合計ジャッジ時間 | 9,949 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 2 ms
5,376 KB |
testcase_03 | AC | 2 ms
5,376 KB |
testcase_04 | AC | 31 ms
5,376 KB |
testcase_05 | AC | 31 ms
5,632 KB |
testcase_06 | AC | 34 ms
5,760 KB |
testcase_07 | AC | 32 ms
5,632 KB |
testcase_08 | AC | 122 ms
15,104 KB |
testcase_09 | AC | 116 ms
14,720 KB |
testcase_10 | AC | 116 ms
14,848 KB |
testcase_11 | AC | 129 ms
15,360 KB |
testcase_12 | AC | 163 ms
18,944 KB |
testcase_13 | AC | 150 ms
17,920 KB |
testcase_14 | AC | 146 ms
17,792 KB |
testcase_15 | AC | 157 ms
18,048 KB |
testcase_16 | AC | 245 ms
20,480 KB |
testcase_17 | AC | 255 ms
20,480 KB |
testcase_18 | AC | 255 ms
19,328 KB |
testcase_19 | AC | 256 ms
19,328 KB |
testcase_20 | AC | 74 ms
7,424 KB |
testcase_21 | AC | 76 ms
7,424 KB |
testcase_22 | AC | 143 ms
11,008 KB |
testcase_23 | AC | 158 ms
11,904 KB |
testcase_24 | AC | 239 ms
17,280 KB |
testcase_25 | AC | 77 ms
7,424 KB |
testcase_26 | AC | 78 ms
7,552 KB |
testcase_27 | AC | 66 ms
7,168 KB |
testcase_28 | AC | 230 ms
16,512 KB |
testcase_29 | AC | 263 ms
18,816 KB |
testcase_30 | AC | 215 ms
16,128 KB |
testcase_31 | AC | 195 ms
15,488 KB |
testcase_32 | AC | 210 ms
19,200 KB |
testcase_33 | AC | 207 ms
16,256 KB |
testcase_34 | WA | - |
testcase_35 | WA | - |
testcase_36 | AC | 110 ms
8,832 KB |
testcase_37 | AC | 162 ms
15,232 KB |
testcase_38 | AC | 215 ms
18,432 KB |
testcase_39 | AC | 160 ms
12,544 KB |
testcase_40 | AC | 168 ms
13,184 KB |
testcase_41 | AC | 163 ms
13,056 KB |
testcase_42 | AC | 72 ms
7,424 KB |
testcase_43 | AC | 221 ms
17,408 KB |
testcase_44 | AC | 34 ms
5,632 KB |
testcase_45 | AC | 169 ms
31,360 KB |
testcase_46 | AC | 168 ms
31,232 KB |
testcase_47 | AC | 29 ms
5,632 KB |
testcase_48 | AC | 61 ms
7,424 KB |
testcase_49 | AC | 63 ms
7,424 KB |
testcase_50 | AC | 57 ms
7,344 KB |
testcase_51 | AC | 60 ms
7,552 KB |
testcase_52 | AC | 57 ms
7,424 KB |
ソースコード
#include<iostream> #include<vector> #include<string> #include<set> #include<map> #define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i) #define rrep(i, start, end) for (int i = (int)start - 1; i >= (int)end; --i) #define all(x) (x).begin(), (x).end() using namespace std; using ll = long long; template<typename T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return 0;} template<typename T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return 0;} class UnionFind { private: vector<int> parent_; vector<int> node_rank_; vector<int> sizes_; public: UnionFind(int node_num): parent_(vector<int>(node_num)), node_rank_(vector<int>(node_num)), sizes_(vector<int>(node_num)) { for (int i = 0; i < node_num; ++i) { parent_[i] = i; node_rank_[i] = 0; sizes_[i] = 1; } } int getRoot(int u) { return parent_[u] == u ? u : parent_[u] = getRoot(parent_[u]); } bool isSame(int u, int v) { return getRoot(u) == getRoot(v); } void unite(int u, int v) { u = getRoot(u); v = getRoot(v); if (u == v) return; if (node_rank_[u] < node_rank_[v]) { parent_[u] = v; sizes_[v] += sizes_[u]; } else { parent_[v] = u; sizes_[u] += sizes_[v]; if (node_rank_[u] == node_rank_[v]) { node_rank_[u]++; } } } int getSize(int u) { return sizes_[getRoot(u)]; } }; void dfs(const vector<vector<int>>& graph, vector<bool>& seen, vector<bool>& finished, int node, int& pos) { seen[node] = true; for (auto& next_node : graph[node]) { if (finished[next_node]) { continue; } if (seen[next_node] && !finished[next_node]) { pos = next_node; return; } dfs(graph, seen, finished, next_node, pos); if (pos != -1) { return; } } finished[node] = true; } int main() { cin.tie(0); ios::sync_with_stdio(false); int N, M; cin >> N >> M; vector<int> A(M), B(M), C(M); rep(i, 0, M) { cin >> A[i] >> B[i] >> C[i]; --A[i], --B[i]; } UnionFind uf(N); rep(i, 0, M) { if (C[i] == 1) { uf.unite(A[i], B[i]); } } set<int> S; rep(i, 0, N) { S.insert(uf.getRoot(i)); } map<int, int> node_map; int node = 0; for (auto s : S) { node_map[s] = node++; } vector<vector<int>> graph(node); rep(i, 0, M) { if (C[i] == 2) { int u = node_map[uf.getRoot(A[i])]; int v = node_map[uf.getRoot(B[i])]; graph[u].push_back(v); } } vector<bool> seen(node, false), finished(node, false); int pos = -1; rep(i, 0, node) { if (!finished[i]) { pos = -1; dfs(graph, seen, finished, i, pos); if (pos != -1) { cout << "Yes" << endl; return 0; } } } cout << "No" << endl; return 0; }