結果
問題 | No.1023 Cyclic Tour |
ユーザー | ei13337 |
提出日時 | 2020-04-10 22:58:48 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,214 bytes |
コンパイル時間 | 1,709 ms |
コンパイル使用メモリ | 124,536 KB |
実行使用メモリ | 21,468 KB |
最終ジャッジ日時 | 2023-10-14 04:02:51 |
合計ジャッジ時間 | 9,227 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,352 KB |
testcase_01 | AC | 2 ms
4,348 KB |
testcase_02 | AC | 2 ms
4,352 KB |
testcase_03 | AC | 1 ms
4,352 KB |
testcase_04 | AC | 64 ms
9,600 KB |
testcase_05 | AC | 64 ms
9,624 KB |
testcase_06 | AC | 74 ms
10,920 KB |
testcase_07 | AC | 67 ms
10,116 KB |
testcase_08 | AC | 63 ms
11,704 KB |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | AC | 65 ms
12,040 KB |
testcase_12 | AC | 58 ms
13,136 KB |
testcase_13 | AC | 56 ms
12,488 KB |
testcase_14 | WA | - |
testcase_15 | AC | 59 ms
12,564 KB |
testcase_16 | AC | 117 ms
15,888 KB |
testcase_17 | AC | 117 ms
16,240 KB |
testcase_18 | AC | 119 ms
15,708 KB |
testcase_19 | AC | 114 ms
15,344 KB |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | AC | 124 ms
11,772 KB |
testcase_23 | WA | - |
testcase_24 | AC | 118 ms
13,984 KB |
testcase_25 | AC | 120 ms
11,244 KB |
testcase_26 | AC | 112 ms
10,988 KB |
testcase_27 | AC | 101 ms
10,712 KB |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | WA | - |
testcase_32 | WA | - |
testcase_33 | AC | 122 ms
13,356 KB |
testcase_34 | AC | 120 ms
10,856 KB |
testcase_35 | AC | 123 ms
11,188 KB |
testcase_36 | WA | - |
testcase_37 | AC | 116 ms
13,700 KB |
testcase_38 | WA | - |
testcase_39 | AC | 120 ms
12,208 KB |
testcase_40 | AC | 114 ms
12,348 KB |
testcase_41 | WA | - |
testcase_42 | AC | 122 ms
11,172 KB |
testcase_43 | AC | 98 ms
13,224 KB |
testcase_44 | AC | 61 ms
9,376 KB |
testcase_45 | AC | 82 ms
21,396 KB |
testcase_46 | AC | 83 ms
21,468 KB |
testcase_47 | AC | 61 ms
13,796 KB |
testcase_48 | AC | 94 ms
10,732 KB |
testcase_49 | AC | 88 ms
10,968 KB |
testcase_50 | AC | 91 ms
10,528 KB |
testcase_51 | AC | 90 ms
10,552 KB |
testcase_52 | AC | 92 ms
10,660 KB |
ソースコード
#include <iostream> #include <vector> #include <map> #include <set> #include <unordered_set> #include <unordered_map> #include <stack> #include <queue> #include <algorithm> #include <cassert> #include <random> #include <iomanip> #include <bitset> #define FOR(i, n, m) for(ll i = n; i < (int)m; i++) #define REP(i, n) FOR(i, 0, n) #define ALL(v) v.begin(), v.end() #define pb push_back using namespace std; using ll = long long; using P = pair<ll, ll>; constexpr ll inf = 1000000000; constexpr ll mod = 998244353; constexpr long double eps = 1e-9; struct Edge { int to; int ty; }; vector<vector<Edge>> g; vector<vector<int>> ng; void dfs(int v, vector<int>& gr, int c) { gr[v] = c; for(auto elm: g[v]) { if(gr[elm.to] != -1 || elm.ty == 2) continue; dfs(elm.to, gr, c); } return; } bool dfs2(int v, vector<bool>& used) { used[v] = true; bool ret = false; for(auto elm: ng[v]) { if(used[elm]) ret = true; else ret = ret | dfs2(elm, used); } return ret; } int main() { cin.tie(0); ios::sync_with_stdio(false); int n, m; cin >> n >> m; g.resize(n); REP(i, m) { int a, b, c; cin >> a >> b >> c; a--; b--; if(c == 1) { g[a].pb({b, c}); g[b].pb({a, c}); } else { g[a].pb({b, c}); } } vector<int> gr(n, -1), grc, grec; int c = 0; REP(i, n) { if(gr[i] != -1) continue; dfs(i, gr, c); c++; } grc.assign(c, 0); grec.assign(c, 0); ng.resize(c); REP(i, n) { grc[gr[i]]++; for(auto elm: g[i]) { if(gr[i] != gr[elm.to]) { ng[gr[i]].pb(gr[elm.to]); } else { if(elm.ty == 2 || i < elm.to) grec[gr[i]]++; } } } REP(i, c) { if(grc[i] <= grec[i]) { cout << "Yes" << endl; return 0; } } REP(i, c) { sort(ng[i].begin(), ng[i].end()); ng[i].erase(unique(ng[i].begin(), ng[i].end()), ng[i].end()); } vector<bool> used(c, false); if(dfs2(0, used)) cout << "Yes" << endl; else cout << "No" << endl; return 0; }