結果
問題 | No.1023 Cyclic Tour |
ユーザー |
![]() |
提出日時 | 2020-04-10 23:16:24 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 922 bytes |
コンパイル時間 | 2,148 ms |
コンパイル使用メモリ | 199,236 KB |
最終ジャッジ日時 | 2025-01-09 16:50:24 |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 WA * 1 |
other | AC * 30 WA * 18 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 (visited.at(next.second)) continue;if (next.first == term) return 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;}