結果
| 問題 |
No.1023 Cyclic Tour
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-03-12 09:50:00 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,942 bytes |
| コンパイル時間 | 1,309 ms |
| コンパイル使用メモリ | 137,952 KB |
| 最終ジャッジ日時 | 2025-01-19 13:47:06 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 39 WA * 10 |
ソースコード
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <array>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <cstring>
#include <unordered_map>
#include <unordered_set>
using namespace std;
using ll = long long;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;
template<class T>
inline bool chmax(T& x, T y){
if(x < y){
x = y;
return true;
}
return false;
}
template<class T>
inline bool chmin(T& x, T y){
if(x > y){
x = y;
return true;
}
return false;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N, M;
cin >> N >> M;
using edge = pair<int, int>;
vector<vector<edge>> g(N);
for(int i = 0; i < M; ++i){
int a, b, c;
cin >> a >> b >> c;
--a, --b;
if(c == 1){
g[a].emplace_back(b, i);
g[b].emplace_back(a, i);
}
else{
g[a].emplace_back(b, i);
}
}
vector<int> timestamp(N, -1), used(M);
int t = 0;
auto dfs = [&](auto&& self, int from, int s) -> void {
timestamp[from] = t++;
for(auto [to, edge_id] : g[from]){
if(used[edge_id]) continue;
used[edge_id] = true;
if(timestamp[to] == -1){
self(self, to, s);
}
else if(timestamp[to] >= s){
cout << "Yes\n";
exit(0);
}
}
};
for(int i = 0; i < N; ++i){
if(timestamp[i] == -1) dfs(dfs, i, t);
}
cout << "No\n";
return 0;
}