結果

問題 No.1023 Cyclic Tour
ユーザー chocoruskchocorusk
提出日時 2020-03-05 21:46:30
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,301 bytes
コンパイル時間 698 ms
コンパイル使用メモリ 75,976 KB
実行使用メモリ 15,744 KB
最終ジャッジ日時 2024-04-23 19:04:12
合計ジャッジ時間 8,661 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,016 KB
testcase_01 AC 3 ms
6,144 KB
testcase_02 AC 3 ms
6,144 KB
testcase_03 AC 3 ms
5,888 KB
testcase_04 AC 73 ms
7,552 KB
testcase_05 AC 69 ms
7,552 KB
testcase_06 AC 79 ms
7,808 KB
testcase_07 AC 73 ms
7,552 KB
testcase_08 AC 83 ms
9,256 KB
testcase_09 AC 75 ms
9,344 KB
testcase_10 AC 73 ms
9,344 KB
testcase_11 AC 83 ms
9,216 KB
testcase_12 AC 80 ms
9,856 KB
testcase_13 AC 75 ms
9,472 KB
testcase_14 AC 75 ms
9,600 KB
testcase_15 AC 81 ms
9,600 KB
testcase_16 AC 148 ms
12,288 KB
testcase_17 AC 155 ms
12,616 KB
testcase_18 AC 158 ms
12,544 KB
testcase_19 AC 150 ms
12,412 KB
testcase_20 AC 137 ms
9,600 KB
testcase_21 AC 151 ms
9,668 KB
testcase_22 AC 151 ms
10,112 KB
testcase_23 AC 151 ms
10,240 KB
testcase_24 AC 154 ms
10,880 KB
testcase_25 AC 137 ms
9,472 KB
testcase_26 AC 136 ms
9,576 KB
testcase_27 AC 135 ms
9,344 KB
testcase_28 AC 147 ms
10,752 KB
testcase_29 AC 142 ms
11,008 KB
testcase_30 AC 148 ms
10,764 KB
testcase_31 AC 139 ms
10,624 KB
testcase_32 AC 141 ms
12,160 KB
testcase_33 AC 147 ms
11,268 KB
testcase_34 WA -
testcase_35 WA -
testcase_36 AC 134 ms
9,600 KB
testcase_37 AC 138 ms
11,136 KB
testcase_38 AC 139 ms
11,264 KB
testcase_39 AC 142 ms
10,240 KB
testcase_40 AC 150 ms
10,240 KB
testcase_41 AC 142 ms
10,240 KB
testcase_42 AC 139 ms
9,600 KB
testcase_43 AC 137 ms
10,624 KB
testcase_44 AC 71 ms
7,680 KB
testcase_45 AC 88 ms
15,744 KB
testcase_46 AC 86 ms
15,616 KB
testcase_47 AC 68 ms
7,680 KB
testcase_48 AC 139 ms
9,396 KB
testcase_49 AC 139 ms
9,388 KB
testcase_50 AC 138 ms
9,396 KB
testcase_51 AC 132 ms
9,392 KB
testcase_52 AC 138 ms
9,388 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
struct unionfind{
    vector<int> par, sz;
    unionfind() {}
    unionfind(int n):par(n), sz(n, 1){
        for(int i=0; i<n; i++) par[i]=i;
    }
    int find(int x){
        if(par[x]==x) return x;
        return par[x]=find(par[x]);
    }
    void unite(int x, int y){
        x=find(x); y=find(y);
        if(x==y) return;
        if(sz[x]>sz[y]) swap(x, y);
        par[x]=y;
        sz[y]+=sz[x];
    }
    bool same(int x, int y){
        return find(x)==find(y);
    }
    int size(int x){
        return sz[find(x)];
    }
};
int n, m;
int a[200020], b[200020], c[200020];
vector<int> g[100010];
bool used[100010];
bool finish[100010];
bool ok;
void dfs(int x){
	used[x]=1;
	for(auto y:g[x]){
		if(used[y] && !finish[y]) ok=1;
		if(!used[y]) dfs(y);
	}
	finish[x]=1;
}
int main()
{
    cin>>n>>m;
	for(int i=0; i<m; i++){
		cin>>a[i]>>b[i]>>c[i];
		a[i]--; b[i]--;
	}
	unionfind uf(n);
	for(int i=0; i<m; i++){
		if(c[i]==1){
			uf.unite(a[i], b[i]);
		}
	}
	for(int i=0; i<m; i++){
		if(c[i]==2) g[uf.find(a[i])].push_back(uf.find(b[i]));
	}
	for(int i=0; i<n; i++){
		if(used[i]) continue;
		dfs(i);
		if(ok){
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	cout<<"No"<<endl;
    return 0;
}
0