結果
| 問題 | No.1023 Cyclic Tour |
| コンテスト | |
| ユーザー |
chocorusk
|
| 提出日時 | 2020-03-08 02:38:30 |
| 言語 | C++14 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,054 bytes |
| 記録 | |
| コンパイル時間 | 941 ms |
| コンパイル使用メモリ | 81,828 KB |
| 実行使用メモリ | 16,384 KB |
| 最終ジャッジ日時 | 2024-10-15 19:56:07 |
| 合計ジャッジ時間 | 10,265 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 44 TLE * 1 -- * 4 |
ソースコード
#include <cstdio>
#include <vector>
#include <algorithm>
#include <random>
using namespace std;
using P=pair<int, int>;
int n, m;
int a[200020], b[200020], c[200020];
vector<P> g[100010];
bool used[400040], finish[400040], ok;
void dfs(int x, int prev){
if(ok) return;
for(auto p:g[x]){
if(ok) return;
int y=p.first, i=p.second;
if(finish[i] || abs(i-prev)==m) continue;
if(used[i]){
ok=1;
return;
}else{
used[i]=1;
dfs(y, i);
}
finish[i]=1;
}
}
int main()
{
scanf("%d %d", &n, &m);
for(int i=0; i<m; i++){
scanf("%d %d %d", &a[i], &b[i], &c[i]);
a[i]--; b[i]--;
g[a[i]].push_back({b[i], i});
if(c[i]==1) g[b[i]].push_back({a[i], i+m});
}
vector<int> ind(n);
mt19937 mt(334);
iota(ind.begin(), ind.end(), 0);
shuffle(ind.begin(), ind.end(), mt);
for(auto i:ind){
dfs(i, 1000000007);
if(ok){
printf("Yes\n");
return 0;
}
}
printf("No\n");
return 0;
}
chocorusk