結果
問題 | No.1023 Cyclic Tour |
ユーザー | TAISA_ |
提出日時 | 2020-04-10 22:16:48 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 169 ms / 2,000 ms |
コード長 | 2,903 bytes |
コンパイル時間 | 2,990 ms |
コンパイル使用メモリ | 208,960 KB |
最終ジャッジ日時 | 2025-01-09 16:15:21 |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 3 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,248 KB |
testcase_02 | AC | 2 ms
5,248 KB |
testcase_03 | AC | 2 ms
5,248 KB |
testcase_04 | AC | 35 ms
7,424 KB |
testcase_05 | AC | 36 ms
7,296 KB |
testcase_06 | AC | 38 ms
7,680 KB |
testcase_07 | AC | 38 ms
7,424 KB |
testcase_08 | AC | 46 ms
8,832 KB |
testcase_09 | AC | 90 ms
20,484 KB |
testcase_10 | AC | 94 ms
20,572 KB |
testcase_11 | AC | 102 ms
21,344 KB |
testcase_12 | AC | 109 ms
22,532 KB |
testcase_13 | AC | 106 ms
21,568 KB |
testcase_14 | AC | 102 ms
21,284 KB |
testcase_15 | AC | 110 ms
21,752 KB |
testcase_16 | AC | 157 ms
22,944 KB |
testcase_17 | AC | 166 ms
23,088 KB |
testcase_18 | AC | 169 ms
21,784 KB |
testcase_19 | AC | 164 ms
21,572 KB |
testcase_20 | AC | 90 ms
20,300 KB |
testcase_21 | AC | 93 ms
21,140 KB |
testcase_22 | AC | 122 ms
21,608 KB |
testcase_23 | AC | 134 ms
21,844 KB |
testcase_24 | AC | 156 ms
24,056 KB |
testcase_25 | AC | 90 ms
20,472 KB |
testcase_26 | AC | 90 ms
20,396 KB |
testcase_27 | AC | 87 ms
19,456 KB |
testcase_28 | AC | 156 ms
23,228 KB |
testcase_29 | AC | 157 ms
23,736 KB |
testcase_30 | AC | 152 ms
23,736 KB |
testcase_31 | AC | 139 ms
23,152 KB |
testcase_32 | AC | 144 ms
22,432 KB |
testcase_33 | AC | 145 ms
23,372 KB |
testcase_34 | AC | 28 ms
8,320 KB |
testcase_35 | AC | 57 ms
8,576 KB |
testcase_36 | AC | 104 ms
21,100 KB |
testcase_37 | AC | 132 ms
22,164 KB |
testcase_38 | AC | 159 ms
22,648 KB |
testcase_39 | AC | 125 ms
21,900 KB |
testcase_40 | AC | 129 ms
21,996 KB |
testcase_41 | AC | 134 ms
21,944 KB |
testcase_42 | AC | 71 ms
8,832 KB |
testcase_43 | AC | 70 ms
9,728 KB |
testcase_44 | AC | 56 ms
18,492 KB |
testcase_45 | AC | 135 ms
28,040 KB |
testcase_46 | AC | 142 ms
25,096 KB |
testcase_47 | AC | 56 ms
18,716 KB |
testcase_48 | AC | 96 ms
20,852 KB |
testcase_49 | AC | 96 ms
20,840 KB |
testcase_50 | AC | 95 ms
20,972 KB |
testcase_51 | AC | 152 ms
8,832 KB |
testcase_52 | AC | 158 ms
9,216 KB |
ソースコード
#include <bits/stdc++.h>#define all(vec) vec.begin(), vec.end()#define pb push_back#define eb emplace_backusing namespace std;using ll = long long;using P = pair<ll, ll>;using V = vector<int>;using VL = vector<ll>;constexpr ll INF = (1LL << 30) - 1LL;constexpr ll MOD = 1e9 + 7;constexpr int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};template <class T>void chmin(T &a, T b) { a = min(a, b); }template <class T>void chmax(T &a, T b) { a = max(a, b); }void ok() { cerr << "ok" << endl; }struct UnionFind {vector<int> par, sz;UnionFind(int n) {par.resize(n);sz.resize(n, 1);iota(all(par), 0);}inline int find(int x) {if (x == par[x]) return x;return par[x] = find(par[x]);}void unite(int u, int v) {u = find(u), v = find(v);if (u == v) return;if (sz[u] < sz[v]) swap(u, v);par[v] = u;sz[u] += sz[v];}inline bool same(int u, int v) {return find(u) == find(v);}};vector<vector<int>> G;struct SCC {int n;vector<int> ord, vis, cm;vector<vector<int>> bl, rG;SCC(int n) : n(n), bl(n), rG(n), cm(n), vis(n) {}void dfs(int i) {vis[i] = 1;for (auto &e : G[i]) {if (vis[e]) continue;dfs(e);}ord.eb(i);}void rdfs(int i, int c) {vis[i] = 1;bl[c].eb(i);cm[i] = c;for (auto &e : rG[i]) {if (vis[e]) continue;rdfs(e, c);}}void build() {for (int i = 0; i < n; i++) {for (auto &e : G[i]) {rG[e].eb(i);}}for (int i = 0; i < n; i++) {if (!vis[i]) dfs(i);}reverse(all(ord));vis.assign(n, 0);int k = 0;for (auto &e : ord) {if (!vis[e]) {bl.eb(vector<int>());rdfs(e, k);k++;}}}};int main() {cin.tie(0);ios::sync_with_stdio(0);int n, m;cin >> n >> m;UnionFind uf(n);V a(m), b(m), c(m);G.resize(n);for (int i = 0; i < m; i++) {cin >> a[i] >> b[i] >> c[i];--a[i];--b[i];if (c[i] == 1) {if (uf.same(a[i], b[i])) {cout << "Yes\n";return 0;}uf.unite(a[i], b[i]);}}for (int i = 0; i < m; i++) {if (c[i] == 2) {if (uf.same(a[i], b[i])) {cout << "Yes\n";return 0;}G[uf.find(a[i])].eb(uf.find(b[i]));}}SCC scc(n);scc.build();for (int i = 0; i < n; i++) {if (scc.bl[i].size() > 1) {cout << "Yes\n";return 0;}}cout << "No\n";return 0;}