結果

問題 No.1023 Cyclic Tour
ユーザー trineutron
提出日時 2020-04-10 23:09:35
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 1,027 bytes
コンパイル時間 4,134 ms
コンパイル使用メモリ 199,600 KB
最終ジャッジ日時 2025-01-09 16:46:22
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 25 WA * 5 TLE * 4 MLE * 15
権限があれば一括ダウンロードができます

ソースコード

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) {
    for (auto next : to.at(city)) {
        if (next.second == road) continue;
        if (next.first == term) return true;
        if (visited.at(next.first)) continue;
        if (dfs(to, visited, next.first, next.second, term)) return true;
        visited.at(next.first) = 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(n);
    for (int i = 0; i < n; i++) {
        if (!visited.at(i)) {
            if (dfs(to, visited, i, -1, i)) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
}
0