結果

問題 No.1023 Cyclic Tour
ユーザー tapienrutapienru
提出日時 2020-05-16 23:47:52
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,277 bytes
コンパイル時間 5,030 ms
コンパイル使用メモリ 215,808 KB
実行使用メモリ 19,340 KB
最終ジャッジ日時 2023-10-24 06:00:04
合計ジャッジ時間 13,214 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 86 ms
12,212 KB
testcase_05 AC 83 ms
12,476 KB
testcase_06 AC 102 ms
14,324 KB
testcase_07 AC 93 ms
13,268 KB
testcase_08 AC 69 ms
10,628 KB
testcase_09 AC 69 ms
10,364 KB
testcase_10 AC 68 ms
10,364 KB
testcase_11 AC 75 ms
10,892 KB
testcase_12 AC 65 ms
10,684 KB
testcase_13 AC 62 ms
10,100 KB
testcase_14 AC 57 ms
10,100 KB
testcase_15 AC 58 ms
10,100 KB
testcase_16 AC 113 ms
14,588 KB
testcase_17 AC 118 ms
14,852 KB
testcase_18 AC 117 ms
14,852 KB
testcase_19 AC 109 ms
14,588 KB
testcase_20 AC 131 ms
14,060 KB
testcase_21 AC 137 ms
14,324 KB
testcase_22 AC 130 ms
13,532 KB
testcase_23 AC 129 ms
13,796 KB
testcase_24 AC 119 ms
13,268 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 119 ms
13,004 KB
testcase_29 AC 110 ms
12,740 KB
testcase_30 AC 126 ms
13,532 KB
testcase_31 AC 133 ms
13,796 KB
testcase_32 AC 134 ms
15,644 KB
testcase_33 AC 145 ms
14,588 KB
testcase_34 AC 137 ms
13,268 KB
testcase_35 AC 153 ms
14,324 KB
testcase_36 AC 153 ms
13,796 KB
testcase_37 AC 137 ms
15,116 KB
testcase_38 AC 122 ms
13,532 KB
testcase_39 AC 137 ms
13,532 KB
testcase_40 AC 137 ms
13,268 KB
testcase_41 AC 136 ms
13,268 KB
testcase_42 WA -
testcase_43 AC 121 ms
12,476 KB
testcase_44 AC 88 ms
12,212 KB
testcase_45 AC 65 ms
16,964 KB
testcase_46 AC 67 ms
19,340 KB
testcase_47 AC 77 ms
15,644 KB
testcase_48 AC 124 ms
13,352 KB
testcase_49 AC 125 ms
13,768 KB
testcase_50 AC 123 ms
13,336 KB
testcase_51 AC 125 ms
13,348 KB
testcase_52 AC 127 ms
13,332 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<pair<int, int>>> G(n + 1);
    vector<pair<int, int>> E(m);
    vector<int> sp(n + 1);
    sp[0] = 2;
    for (int i = 0; i < m; ++i) {
        int u, v, c; cin >> u >> v >> c;
        E[i] = {u, v};
        G[u].emplace_back(-c, i);
        if (c == 1) G[v].emplace_back(-c, i);
        else sp[u] = -1;
    }
    for (int i = 1; i <= n; ++i) sort(G[i].begin(), G[i].end());
    vector<int> p(n + 1);
    for (int i = 1; i <= n; ++i) p[i] = i;
    sort(p.begin(), p.end(), [&] (const int& x, const int& y) { return sp[x] < sp[y]; });
    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 (auto& [c, 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 (auto o : p)
        if (!vis[o] && o) dfs(o);
    cout << (ans ? "Yes" : "No") << '\n';
}
0