結果
問題 | No.1023 Cyclic Tour |
ユーザー | ei13337 |
提出日時 | 2020-04-10 23:04:10 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,431 bytes |
コンパイル時間 | 1,538 ms |
コンパイル使用メモリ | 127,588 KB |
実行使用メモリ | 21,864 KB |
最終ジャッジ日時 | 2023-10-14 04:12:16 |
合計ジャッジ時間 | 9,405 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
4,348 KB |
testcase_01 | AC | 2 ms
4,352 KB |
testcase_02 | AC | 1 ms
4,352 KB |
testcase_03 | AC | 1 ms
4,348 KB |
testcase_04 | AC | 66 ms
9,812 KB |
testcase_05 | AC | 67 ms
9,596 KB |
testcase_06 | AC | 78 ms
10,916 KB |
testcase_07 | AC | 71 ms
10,060 KB |
testcase_08 | AC | 65 ms
11,668 KB |
testcase_09 | AC | 73 ms
13,268 KB |
testcase_10 | AC | 72 ms
13,664 KB |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | AC | 67 ms
15,076 KB |
testcase_15 | WA | - |
testcase_16 | AC | 122 ms
17,408 KB |
testcase_17 | AC | 124 ms
18,712 KB |
testcase_18 | AC | 125 ms
16,948 KB |
testcase_19 | AC | 122 ms
17,980 KB |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | AC | 128 ms
11,244 KB |
testcase_26 | AC | 121 ms
10,984 KB |
testcase_27 | AC | 105 ms
10,352 KB |
testcase_28 | AC | 126 ms
15,992 KB |
testcase_29 | AC | 122 ms
17,192 KB |
testcase_30 | AC | 129 ms
15,244 KB |
testcase_31 | AC | 125 ms
14,636 KB |
testcase_32 | AC | 124 ms
15,664 KB |
testcase_33 | AC | 128 ms
15,700 KB |
testcase_34 | AC | 118 ms
10,888 KB |
testcase_35 | AC | 123 ms
11,152 KB |
testcase_36 | WA | - |
testcase_37 | AC | 121 ms
13,972 KB |
testcase_38 | AC | 114 ms
15,476 KB |
testcase_39 | WA | - |
testcase_40 | AC | 123 ms
13,584 KB |
testcase_41 | AC | 125 ms
13,528 KB |
testcase_42 | AC | 123 ms
11,156 KB |
testcase_43 | AC | 103 ms
13,356 KB |
testcase_44 | AC | 67 ms
9,396 KB |
testcase_45 | AC | 85 ms
21,864 KB |
testcase_46 | AC | 66 ms
18,488 KB |
testcase_47 | AC | 63 ms
13,632 KB |
testcase_48 | WA | - |
testcase_49 | WA | - |
testcase_50 | AC | 94 ms
10,572 KB |
testcase_51 | AC | 91 ms
10,664 KB |
testcase_52 | AC | 91 ms
10,548 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); vector<int> indeg(c, 0); REP(i, c) { for(auto adj: ng[i]) indeg[adj]++; } ng.pb({}); REP(i, c) { if(indeg[i] == 0) ng[c].pb(i); } bool ok = false; if((int)ng[c].size() == 0 || dfs2(c, used)) cout << "Yes" << endl; else cout << "No" << endl; return 0; }