結果

問題 No.1023 Cyclic Tour
ユーザー ngtkanangtkana
提出日時 2020-04-10 22:53:07
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,144 bytes
コンパイル時間 2,298 ms
コンパイル使用メモリ 210,280 KB
実行使用メモリ 29,560 KB
最終ジャッジ日時 2023-10-14 03:45:05
合計ジャッジ時間 12,674 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,352 KB
testcase_02 AC 1 ms
4,352 KB
testcase_03 AC 2 ms
4,352 KB
testcase_04 AC 88 ms
21,564 KB
testcase_05 AC 86 ms
21,664 KB
testcase_06 AC 101 ms
23,316 KB
testcase_07 AC 91 ms
22,356 KB
testcase_08 AC 66 ms
18,892 KB
testcase_09 AC 67 ms
18,472 KB
testcase_10 AC 64 ms
18,432 KB
testcase_11 AC 103 ms
19,120 KB
testcase_12 AC 83 ms
17,620 KB
testcase_13 AC 77 ms
16,728 KB
testcase_14 WA -
testcase_15 AC 83 ms
16,904 KB
testcase_16 AC 115 ms
23,600 KB
testcase_17 AC 119 ms
23,740 KB
testcase_18 AC 126 ms
23,472 KB
testcase_19 AC 120 ms
22,904 KB
testcase_20 AC 227 ms
27,312 KB
testcase_21 AC 228 ms
27,652 KB
testcase_22 AC 208 ms
26,388 KB
testcase_23 AC 217 ms
26,508 KB
testcase_24 AC 193 ms
25,348 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 176 ms
26,832 KB
testcase_28 AC 148 ms
25,088 KB
testcase_29 AC 130 ms
23,944 KB
testcase_30 AC 147 ms
26,144 KB
testcase_31 AC 139 ms
26,092 KB
testcase_32 AC 146 ms
27,316 KB
testcase_33 WA -
testcase_34 AC 164 ms
26,564 KB
testcase_35 AC 181 ms
28,192 KB
testcase_36 AC 223 ms
26,956 KB
testcase_37 AC 154 ms
27,444 KB
testcase_38 AC 134 ms
24,464 KB
testcase_39 AC 212 ms
25,716 KB
testcase_40 AC 150 ms
25,828 KB
testcase_41 AC 152 ms
26,000 KB
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 AC 88 ms
26,396 KB
testcase_46 AC 71 ms
26,896 KB
testcase_47 AC 120 ms
29,560 KB
testcase_48 AC 209 ms
25,824 KB
testcase_49 AC 255 ms
26,824 KB
testcase_50 AC 250 ms
28,012 KB
testcase_51 AC 221 ms
28,908 KB
testcase_52 AC 130 ms
24,724 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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(v);
        }
    }
    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';
}
0