結果

問題 No.1023 Cyclic Tour
ユーザー ngtkanangtkana
提出日時 2020-04-10 22:56:26
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,144 bytes
コンパイル時間 5,280 ms
コンパイル使用メモリ 211,236 KB
実行使用メモリ 31,072 KB
最終ジャッジ日時 2023-10-14 03:51:00
合計ジャッジ時間 12,830 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,372 KB
testcase_01 AC 2 ms
4,368 KB
testcase_02 AC 2 ms
4,372 KB
testcase_03 AC 1 ms
4,368 KB
testcase_04 AC 91 ms
23,480 KB
testcase_05 AC 90 ms
23,320 KB
testcase_06 AC 103 ms
25,444 KB
testcase_07 AC 96 ms
24,296 KB
testcase_08 AC 65 ms
18,984 KB
testcase_09 AC 65 ms
18,516 KB
testcase_10 AC 63 ms
18,448 KB
testcase_11 AC 103 ms
19,400 KB
testcase_12 AC 84 ms
17,728 KB
testcase_13 AC 77 ms
16,736 KB
testcase_14 WA -
testcase_15 AC 80 ms
16,908 KB
testcase_16 AC 117 ms
23,588 KB
testcase_17 AC 121 ms
23,724 KB
testcase_18 AC 126 ms
23,480 KB
testcase_19 AC 118 ms
22,976 KB
testcase_20 AC 231 ms
28,856 KB
testcase_21 AC 238 ms
29,788 KB
testcase_22 AC 224 ms
27,268 KB
testcase_23 AC 218 ms
27,312 KB
testcase_24 AC 196 ms
25,476 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 182 ms
28,392 KB
testcase_28 AC 145 ms
25,412 KB
testcase_29 AC 126 ms
23,992 KB
testcase_30 AC 147 ms
26,284 KB
testcase_31 AC 138 ms
26,252 KB
testcase_32 AC 146 ms
27,540 KB
testcase_33 WA -
testcase_34 AC 162 ms
27,332 KB
testcase_35 AC 178 ms
29,676 KB
testcase_36 AC 227 ms
28,184 KB
testcase_37 AC 150 ms
27,900 KB
testcase_38 AC 129 ms
24,536 KB
testcase_39 AC 208 ms
26,120 KB
testcase_40 AC 149 ms
26,324 KB
testcase_41 AC 153 ms
26,376 KB
testcase_42 WA -
testcase_43 AC 52 ms
16,240 KB
testcase_44 WA -
testcase_45 AC 87 ms
26,352 KB
testcase_46 AC 67 ms
26,824 KB
testcase_47 AC 126 ms
31,072 KB
testcase_48 AC 260 ms
28,888 KB
testcase_49 AC 282 ms
29,232 KB
testcase_50 AC 259 ms
28,876 KB
testcase_51 AC 218 ms
29,160 KB
testcase_52 AC 203 ms
29,408 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(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';
}
0