結果
| 問題 |
No.1023 Cyclic Tour
|
| コンテスト | |
| ユーザー |
trineutron
|
| 提出日時 | 2020-04-10 23:12:25 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 965 bytes |
| コンパイル時間 | 6,006 ms |
| コンパイル使用メモリ | 200,132 KB |
| 最終ジャッジ日時 | 2025-01-09 16:46:56 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge6 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 32 WA * 16 TLE * 1 |
ソースコード
#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;
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;
}
trineutron