結果
問題 | No.1023 Cyclic Tour |
ユーザー | hiroaki0615 |
提出日時 | 2020-04-10 23:12:04 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,284 bytes |
コンパイル時間 | 1,085 ms |
コンパイル使用メモリ | 95,756 KB |
実行使用メモリ | 31,360 KB |
最終ジャッジ日時 | 2024-09-16 00:07:57 |
合計ジャッジ時間 | 9,987 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
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 | 3 ms
5,376 KB |
testcase_04 | AC | 30 ms
5,504 KB |
testcase_05 | AC | 31 ms
5,504 KB |
testcase_06 | AC | 34 ms
5,760 KB |
testcase_07 | AC | 32 ms
5,760 KB |
testcase_08 | AC | 127 ms
15,104 KB |
testcase_09 | AC | 118 ms
14,720 KB |
testcase_10 | AC | 120 ms
14,976 KB |
testcase_11 | AC | 142 ms
15,488 KB |
testcase_12 | AC | 176 ms
18,944 KB |
testcase_13 | AC | 157 ms
17,920 KB |
testcase_14 | AC | 154 ms
17,792 KB |
testcase_15 | AC | 166 ms
18,048 KB |
testcase_16 | AC | 261 ms
20,480 KB |
testcase_17 | AC | 272 ms
20,608 KB |
testcase_18 | AC | 262 ms
19,456 KB |
testcase_19 | AC | 271 ms
19,456 KB |
testcase_20 | AC | 74 ms
7,424 KB |
testcase_21 | AC | 77 ms
7,296 KB |
testcase_22 | AC | 143 ms
11,136 KB |
testcase_23 | AC | 160 ms
11,776 KB |
testcase_24 | AC | 236 ms
17,280 KB |
testcase_25 | AC | 78 ms
7,424 KB |
testcase_26 | AC | 79 ms
7,552 KB |
testcase_27 | AC | 67 ms
7,296 KB |
testcase_28 | AC | 226 ms
16,640 KB |
testcase_29 | AC | 257 ms
18,816 KB |
testcase_30 | AC | 211 ms
16,128 KB |
testcase_31 | AC | 190 ms
15,488 KB |
testcase_32 | AC | 204 ms
19,328 KB |
testcase_33 | AC | 210 ms
16,256 KB |
testcase_34 | WA | - |
testcase_35 | WA | - |
testcase_36 | AC | 110 ms
8,832 KB |
testcase_37 | AC | 168 ms
15,232 KB |
testcase_38 | AC | 221 ms
18,560 KB |
testcase_39 | AC | 164 ms
12,416 KB |
testcase_40 | AC | 169 ms
13,312 KB |
testcase_41 | AC | 166 ms
13,184 KB |
testcase_42 | AC | 72 ms
7,424 KB |
testcase_43 | AC | 223 ms
17,408 KB |
testcase_44 | AC | 34 ms
5,632 KB |
testcase_45 | AC | 171 ms
31,360 KB |
testcase_46 | AC | 170 ms
31,360 KB |
testcase_47 | AC | 29 ms
5,760 KB |
testcase_48 | AC | 61 ms
7,552 KB |
testcase_49 | AC | 63 ms
7,456 KB |
testcase_50 | AC | 57 ms
7,348 KB |
testcase_51 | AC | 59 ms
7,584 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, bool& pos) { seen[node] = true; for (auto& next_node : graph[node]) { if (finished[next_node]) { continue; } if (seen[next_node] && !finished[next_node]) { pos = true; return; } dfs(graph, seen, finished, next_node, pos); if (pos) { 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); rep(i, 0, node) { if (!finished[i]) { bool pos = false; dfs(graph, seen, finished, i, pos); if (pos) { cout << "Yes" << endl; return 0; } } } cout << "No" << endl; return 0; }