結果
| 問題 | No.1023 Cyclic Tour |
| コンテスト | |
| ユーザー |
ngtkana
|
| 提出日時 | 2020-04-10 22:56:26 |
| 言語 | C++17 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,144 bytes |
| 記録 | |
| コンパイル時間 | 2,241 ms |
| コンパイル使用メモリ | 204,276 KB |
| 最終ジャッジ日時 | 2025-01-09 16:37:58 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 43 WA * 6 |
ソースコード
#include<bits/stdc++.h>
#define ALL(v) std::begin(v),std::end(v)
using lint=long long;
using ld=long double;
void yes(){
std::cout<<"Yes"<<'\n';
exit(0);
}
int main(){
std::cin.tie(nullptr);std::ios_base::sync_with_stdio(false);
std::cout.setf(std::ios_base::fixed);std::cout.precision(15);
lint n,m;std::cin>>n>>m;
std::vector<std::vector<lint>>g(n);
std::vector<std::set<lint>>sets(n);
while(m--){
lint u,v,c;std::cin>>u>>v>>c;u--,v--;
if(sets.at(u).count(v)||c==1&&sets.at(v).count(u))yes();
g.at(u).push_back(v);
sets.at(u).insert(v);
if(c==1){
g.at(v).push_back(u);
sets.at(v).insert(u);
}
}
std::vector<lint>ckd(n,0);
auto dfs=[&](auto&&f,lint x,lint p)->void{
ckd.at(x)=1;
for(lint y:g.at(x)){
if(y==p)continue;
if(ckd.at(y)==1)yes();
if(ckd.at(y)==2)continue;
f(f,y,x);
}
ckd.at(x)=2;
};
for(lint i=0;i<n;i++){
assert(ckd.at(i)!=1);
if(ckd.at(i)==2)continue;
dfs(dfs,i,i);
}
std::cout<<"No"<<'\n';
}
ngtkana