結果

問題 No.1023 Cyclic Tour
ユーザー trineutrontrineutron
提出日時 2020-04-10 23:14:26
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,005 bytes
コンパイル時間 2,120 ms
コンパイル使用メモリ 206,248 KB
実行使用メモリ 16,176 KB
最終ジャッジ日時 2023-10-14 04:45:37
合計ジャッジ時間 16,089 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
8,828 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 WA -
testcase_05 AC 98 ms
8,920 KB
testcase_06 AC 112 ms
10,676 KB
testcase_07 AC 106 ms
10,240 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 104 ms
7,984 KB
testcase_12 AC 94 ms
7,376 KB
testcase_13 AC 86 ms
7,288 KB
testcase_14 AC 81 ms
7,180 KB
testcase_15 AC 93 ms
7,264 KB
testcase_16 AC 165 ms
10,936 KB
testcase_17 WA -
testcase_18 AC 175 ms
12,028 KB
testcase_19 AC 157 ms
8,804 KB
testcase_20 AC 200 ms
10,244 KB
testcase_21 AC 203 ms
10,104 KB
testcase_22 AC 186 ms
9,640 KB
testcase_23 AC 196 ms
9,560 KB
testcase_24 AC 188 ms
9,312 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 180 ms
9,064 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 167 ms
9,884 KB
testcase_32 AC 172 ms
11,816 KB
testcase_33 AC 181 ms
10,480 KB
testcase_34 WA -
testcase_35 WA -
testcase_36 AC 200 ms
9,840 KB
testcase_37 AC 169 ms
11,220 KB
testcase_38 AC 161 ms
9,616 KB
testcase_39 AC 191 ms
9,344 KB
testcase_40 AC 174 ms
9,392 KB
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 AC 102 ms
16,156 KB
testcase_46 AC 97 ms
16,176 KB
testcase_47 AC 106 ms
16,156 KB
testcase_48 AC 665 ms
9,244 KB
testcase_49 TLE -
testcase_50 -- -
testcase_51 -- -
testcase_52 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

using graph = vector<vector<pair<int, int>>>;

bool dfs(const graph &to, vector<bool> &visited, int city, int road, int term) {
    visited.at(road) = true;
    for (auto next : to.at(city)) {
        if (next.second == road) continue;
        if (next.first == term) return true;
        if (visited.at(next.second)) continue;
        visited.at(next.second) = true;
        if (dfs(to, visited, next.first, next.second, term)) return true;
    }
    return false;
}

int main() {
    int n, m;
    cin >> n >> m;
    graph to(n);
    for (int i = 0; i < m; i++) {
        int a, b, c;
        cin >> a >> b >> c;
        a--; b--;
        to.at(a).emplace_back(b, i);
        if (c == 1) {
            to.at(b).emplace_back(a, i);
        }
    }
    vector<bool> visited(m + 1);
    for (int i = 0; i < n; i++) {
        if (dfs(to, visited, i, m, i)) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}
0