結果

問題 No.1023 Cyclic Tour
ユーザー ngtkanangtkana
提出日時 2020-04-10 23:21:01
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,844 bytes
コンパイル時間 2,476 ms
コンパイル使用メモリ 214,756 KB
実行使用メモリ 25,932 KB
最終ジャッジ日時 2023-10-14 05:28:22
合計ジャッジ時間 14,504 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 203 ms
21,956 KB
testcase_05 AC 205 ms
21,968 KB
testcase_06 AC 235 ms
24,292 KB
testcase_07 AC 208 ms
22,936 KB
testcase_08 AC 72 ms
15,128 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 90 ms
15,580 KB
testcase_12 AC 53 ms
13,144 KB
testcase_13 AC 50 ms
12,532 KB
testcase_14 WA -
testcase_15 AC 51 ms
12,888 KB
testcase_16 AC 78 ms
16,312 KB
testcase_17 AC 86 ms
17,032 KB
testcase_18 AC 82 ms
16,136 KB
testcase_19 AC 81 ms
15,828 KB
testcase_20 AC 279 ms
24,156 KB
testcase_21 AC 285 ms
24,920 KB
testcase_22 AC 215 ms
22,620 KB
testcase_23 AC 214 ms
22,252 KB
testcase_24 AC 131 ms
19,080 KB
testcase_25 AC 259 ms
24,720 KB
testcase_26 AC 233 ms
24,600 KB
testcase_27 AC 225 ms
23,420 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 AC 195 ms
20,672 KB
testcase_35 AC 229 ms
23,568 KB
testcase_36 AC 252 ms
23,508 KB
testcase_37 AC 148 ms
22,776 KB
testcase_38 WA -
testcase_39 AC 189 ms
22,304 KB
testcase_40 WA -
testcase_41 WA -
testcase_42 AC 239 ms
24,328 KB
testcase_43 AC 85 ms
16,520 KB
testcase_44 AC 207 ms
22,320 KB
testcase_45 AC 59 ms
20,252 KB
testcase_46 AC 47 ms
20,744 KB
testcase_47 AC 201 ms
25,816 KB
testcase_48 AC 378 ms
25,880 KB
testcase_49 AC 288 ms
25,760 KB
testcase_50 AC 264 ms
25,932 KB
testcase_51 AC 195 ms
24,560 KB
testcase_52 AC 193 ms
25,600 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define ALL(v) std::begin(v),std::end(v)
using lint=long long;
using ld=long double;
#define ENABLE_DEBUG 1
#ifdef NGTKANA
#include<debug.hpp>
#else
#define DEBUG(...)(void)0
#endif
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);
    std::set<std::pair<lint,lint>>set;
    while(m--){
        lint u,v,c;std::cin>>u>>v>>c;u--,v--;
        if(c==1){
            if(set.count(std::pair{u,v}))yes();
            g.at(u).push_back(v);
            g.at(v).push_back(u);
            set.emplace(u,v);
            set.emplace(v,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);
    }
    DEBUG(cmp);
    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';
}
0