結果
問題 |
No.1023 Cyclic Tour
|
ユーザー |
![]() |
提出日時 | 2020-04-10 23:14:26 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,005 bytes |
コンパイル時間 | 2,109 ms |
コンパイル使用メモリ | 199,084 KB |
最終ジャッジ日時 | 2025-01-09 16:48:47 |
ジャッジサーバーID (参考情報) |
judge3 / 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; 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; }