結果

問題 No.1023 Cyclic Tour
ユーザー tapienrutapienru
提出日時 2020-05-16 22:39:43
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 967 bytes
コンパイル時間 3,764 ms
コンパイル使用メモリ 209,568 KB
実行使用メモリ 18,484 KB
最終ジャッジ日時 2023-10-24 04:31:13
合計ジャッジ時間 13,540 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 56 ms
11,092 KB
testcase_05 AC 57 ms
11,092 KB
testcase_06 AC 68 ms
12,676 KB
testcase_07 AC 61 ms
11,884 KB
testcase_08 AC 48 ms
9,772 KB
testcase_09 AC 48 ms
9,508 KB
testcase_10 AC 52 ms
9,508 KB
testcase_11 AC 53 ms
9,772 KB
testcase_12 AC 48 ms
9,508 KB
testcase_13 AC 42 ms
9,244 KB
testcase_14 AC 42 ms
9,244 KB
testcase_15 AC 55 ms
9,244 KB
testcase_16 AC 85 ms
12,940 KB
testcase_17 AC 87 ms
13,204 KB
testcase_18 AC 88 ms
13,204 KB
testcase_19 AC 90 ms
12,940 KB
testcase_20 AC 107 ms
11,884 KB
testcase_21 AC 99 ms
11,884 KB
testcase_22 AC 98 ms
11,620 KB
testcase_23 AC 101 ms
11,620 KB
testcase_24 AC 93 ms
11,620 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 88 ms
12,148 KB
testcase_28 AC 95 ms
11,356 KB
testcase_29 AC 81 ms
11,092 KB
testcase_30 AC 90 ms
11,884 KB
testcase_31 AC 99 ms
12,148 KB
testcase_32 AC 88 ms
14,260 KB
testcase_33 WA -
testcase_34 AC 89 ms
11,356 KB
testcase_35 AC 94 ms
11,884 KB
testcase_36 AC 90 ms
11,940 KB
testcase_37 AC 88 ms
13,468 KB
testcase_38 AC 80 ms
12,148 KB
testcase_39 AC 123 ms
11,620 KB
testcase_40 AC 94 ms
11,676 KB
testcase_41 AC 89 ms
11,356 KB
testcase_42 WA -
testcase_43 AC 80 ms
11,092 KB
testcase_44 WA -
testcase_45 AC 58 ms
18,484 KB
testcase_46 AC 57 ms
18,484 KB
testcase_47 AC 69 ms
18,484 KB
testcase_48 AC 107 ms
12,112 KB
testcase_49 AC 87 ms
12,400 KB
testcase_50 AC 88 ms
12,096 KB
testcase_51 AC 85 ms
12,108 KB
testcase_52 AC 87 ms
12,092 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma gcc optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int n, m; cin >> n >> m;
    vector<vector<int>> G(n + 1);
    vector<pair<int, int>> E(m);
    for (int i = 0; i < m; ++i) {
        int u, v, c; cin >> u >> v >> c;
        E[i] = {u, v};
        G[u].emplace_back(i);
        if (c == 1) G[v].emplace_back(i);
    }
    int ans = 0;
    vector<int> vis(n + 1), stk(n + 1), evis(m);
    function<void(int)> dfs = [&] (int u) {
        vis[u] = stk[u] = 1;
        for (int i : G[u]) {
            if (evis[i]) continue;
            int v = u != E[i].first ? E[i].first : E[i].second;
            if (vis[v] && stk[v]) ans = 1;
            if (!vis[v]) {
                evis[i] = 1;
                dfs(v);
            }
        }
        stk[u] = 0;
    };
    for (int i = 1; i <= n; ++i)
        if (!vis[i]) dfs(i);
    cout << (ans ? "Yes" : "No") << '\n';
}
0