結果
| 問題 |
No.1023 Cyclic Tour
|
| コンテスト | |
| ユーザー |
ngtkana
|
| 提出日時 | 2020-04-10 23:13:20 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,584 bytes |
| コンパイル時間 | 5,793 ms |
| コンパイル使用メモリ | 202,904 KB |
| 最終ジャッジ日時 | 2025-01-09 16:47:29 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 37 WA * 12 |
ソースコード
#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::pair<lint,lint>>arrows;
std::vector<std::vector<lint>>g(n);
while(m--){
lint u,v,c;std::cin>>u>>v>>c;u--,v--;
if(c==1){
g.at(u).push_back(v);
g.at(v).push_back(u);
}
if(c==2){
arrows.emplace_back(u,v);
}
}
lint sz=0;
std::vector<lint>cmp(n,-1);
auto dfs=[&](auto&&f,lint x,lint p)->void{
for(lint y:g.at(x)){
if(y==p)continue;
if(cmp.at(y)!=-1)yes();
cmp.at(y)=cmp.at(x);
f(f,y,x);
}
};
for(lint i=0;i<n;i++){
if(cmp.at(i)!=-1)continue;
cmp.at(i)=sz++;
dfs(dfs,i,i);
}
std::vector<std::vector<lint>>h(sz);
for(auto[u,v]:arrows){
u=cmp.at(u),v=cmp.at(v);
if(u==v)yes();
h.at(u).push_back(v);
}
std::vector<lint>ckd(sz);
auto efs=[&](auto&&f,lint x)->void{
ckd.at(x)=1;
for(lint y:h.at(x)){
if(ckd.at(y)==1)yes();
if(ckd.at(y)==2)continue;
f(f,y);
}
ckd.at(x)=2;
};
for(lint i=0;i<sz;i++){
assert(ckd.at(i)!=1);
if(ckd.at(i)==2)continue;
efs(efs,0);
}
std::cout<<"No"<<'\n';
}
ngtkana