結果

問題 No.1023 Cyclic Tour
ユーザー chocoruskchocorusk
提出日時 2020-03-08 02:38:30
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,054 bytes
コンパイル時間 758 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 18,660 KB
最終ジャッジ日時 2024-04-23 19:07:23
合計ジャッジ時間 8,801 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
11,648 KB
testcase_01 AC 3 ms
6,016 KB
testcase_02 AC 3 ms
6,272 KB
testcase_03 AC 3 ms
6,144 KB
testcase_04 AC 41 ms
11,188 KB
testcase_05 AC 43 ms
11,368 KB
testcase_06 AC 49 ms
11,840 KB
testcase_07 AC 46 ms
11,492 KB
testcase_08 AC 40 ms
10,104 KB
testcase_09 AC 40 ms
10,004 KB
testcase_10 AC 38 ms
10,056 KB
testcase_11 AC 51 ms
10,424 KB
testcase_12 AC 46 ms
9,936 KB
testcase_13 AC 41 ms
9,704 KB
testcase_14 AC 36 ms
9,576 KB
testcase_15 AC 40 ms
9,716 KB
testcase_16 AC 67 ms
12,160 KB
testcase_17 AC 63 ms
12,128 KB
testcase_18 AC 65 ms
12,468 KB
testcase_19 AC 60 ms
12,132 KB
testcase_20 AC 95 ms
13,916 KB
testcase_21 AC 99 ms
14,044 KB
testcase_22 AC 92 ms
13,448 KB
testcase_23 AC 97 ms
13,552 KB
testcase_24 AC 93 ms
12,992 KB
testcase_25 AC 78 ms
13,932 KB
testcase_26 AC 82 ms
14,100 KB
testcase_27 AC 76 ms
13,748 KB
testcase_28 AC 74 ms
12,872 KB
testcase_29 AC 68 ms
12,572 KB
testcase_30 AC 74 ms
13,272 KB
testcase_31 AC 70 ms
13,376 KB
testcase_32 AC 78 ms
15,104 KB
testcase_33 AC 76 ms
14,056 KB
testcase_34 AC 77 ms
13,464 KB
testcase_35 AC 92 ms
14,036 KB
testcase_36 AC 101 ms
13,772 KB
testcase_37 AC 76 ms
14,396 KB
testcase_38 AC 70 ms
13,296 KB
testcase_39 AC 85 ms
13,208 KB
testcase_40 AC 68 ms
13,140 KB
testcase_41 AC 71 ms
13,144 KB
testcase_42 AC 79 ms
13,960 KB
testcase_43 AC 69 ms
12,484 KB
testcase_44 AC 45 ms
11,528 KB
testcase_45 AC 45 ms
15,460 KB
testcase_46 AC 46 ms
16,768 KB
testcase_47 AC 56 ms
16,512 KB
testcase_48 TLE -
testcase_49 -- -
testcase_50 -- -
testcase_51 -- -
testcase_52 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <vector>
#include <algorithm>
#include <random>
using namespace std;
using P=pair<int, int>;
int n, m;
int a[200020], b[200020], c[200020];
vector<P> g[100010];
bool used[400040], finish[400040], ok;
void dfs(int x, int prev){
    if(ok) return;
	for(auto p:g[x]){
        if(ok) return;
        int y=p.first, i=p.second;
        if(finish[i] || abs(i-prev)==m) continue;
		if(used[i]){
            ok=1;
            return;
		}else{
            used[i]=1;
            dfs(y, i);
        }
        finish[i]=1;
	}
}
int main()
{
    scanf("%d %d", &n, &m);
	for(int i=0; i<m; i++){
		scanf("%d %d %d", &a[i], &b[i], &c[i]);
		a[i]--; b[i]--;
        g[a[i]].push_back({b[i], i});
        if(c[i]==1) g[b[i]].push_back({a[i], i+m});
	}
    vector<int> ind(n);
    mt19937 mt(334);
    iota(ind.begin(), ind.end(), 0);
    shuffle(ind.begin(), ind.end(), mt);
    for(auto i:ind){
        dfs(i, 1000000007);
        if(ok){
            printf("Yes\n");
            return 0;
        }
    }
    printf("No\n");
    return 0;
}
0