結果

問題 No.1023 Cyclic Tour
ユーザー kotatsugamekotatsugame
提出日時 2020-04-15 12:40:11
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,217 bytes
コンパイル時間 980 ms
コンパイル使用メモリ 82,028 KB
実行使用メモリ 11,744 KB
最終ジャッジ日時 2024-04-09 18:37:46
合計ジャッジ時間 10,300 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,856 KB
testcase_01 AC 3 ms
6,944 KB
testcase_02 WA -
testcase_03 AC 4 ms
6,940 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 93 ms
9,520 KB
testcase_09 AC 91 ms
9,600 KB
testcase_10 AC 89 ms
9,504 KB
testcase_11 AC 97 ms
9,812 KB
testcase_12 AC 96 ms
10,496 KB
testcase_13 AC 90 ms
10,116 KB
testcase_14 AC 91 ms
10,176 KB
testcase_15 AC 94 ms
10,280 KB
testcase_16 AC 166 ms
11,744 KB
testcase_17 AC 171 ms
11,620 KB
testcase_18 AC 174 ms
11,544 KB
testcase_19 AC 168 ms
11,428 KB
testcase_20 AC 155 ms
8,896 KB
testcase_21 AC 156 ms
9,028 KB
testcase_22 AC 164 ms
9,676 KB
testcase_23 AC 171 ms
9,932 KB
testcase_24 AC 180 ms
10,848 KB
testcase_25 AC 157 ms
8,904 KB
testcase_26 AC 158 ms
8,880 KB
testcase_27 AC 154 ms
8,596 KB
testcase_28 AC 177 ms
10,688 KB
testcase_29 AC 175 ms
11,072 KB
testcase_30 AC 181 ms
10,716 KB
testcase_31 AC 167 ms
10,336 KB
testcase_32 AC 170 ms
10,892 KB
testcase_33 AC 180 ms
10,464 KB
testcase_34 WA -
testcase_35 WA -
testcase_36 AC 161 ms
9,288 KB
testcase_37 AC 164 ms
10,172 KB
testcase_38 AC 168 ms
10,784 KB
testcase_39 AC 170 ms
9,912 KB
testcase_40 AC 169 ms
10,168 KB
testcase_41 AC 171 ms
10,036 KB
testcase_42 WA -
testcase_43 WA -
testcase_44 AC 79 ms
7,456 KB
testcase_45 AC 100 ms
11,360 KB
testcase_46 AC 95 ms
11,488 KB
testcase_47 AC 81 ms
7,048 KB
testcase_48 AC 162 ms
8,796 KB
testcase_49 AC 167 ms
9,208 KB
testcase_50 AC 158 ms
8,800 KB
testcase_51 WA -
testcase_52 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:37:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   37 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
#include<vector>
#include<queue>
using namespace std;
#include<vector>
struct UF{
	int n;
	vector<int>parent,rank;
	UF(int n_=0):n(n_),parent(n_),rank(n_,1)
	{
		for(int i=0;i<n_;i++)parent[i]=i;
	}
	int find(int a){return parent[a]!=a?parent[a]=find(parent[a]):a;}
	bool same(int a,int b){return find(a)==find(b);}
	bool unite(int a,int b)
	{
		a=find(a),b=find(b);
		if(a==b)return false;
		if(rank[a]<rank[b])
		{
			parent[a]=b;
			rank[b]+=rank[a];
		}
		else
		{
			parent[b]=a;
			rank[a]+=rank[b];
		}
		return true;
	}
	int size(int a){return rank[find(a)];}
};
int N,M;
vector<pair<int,int> >edge;
vector<int>G[1<<17];
int cnt[1<<17];
main()
{
	cin>>N>>M;
	UF uf(N);
	for(int i=0;i<M;i++)
	{
		int a,b,c;cin>>a>>b>>c;
		a--,b--;
		if(c==1)uf.unite(a,b);
		else edge.push_back(make_pair(a,b));
	}
	for(pair<int,int>p:edge)
	{
		int u=uf.find(p.first);
		int v=uf.find(p.second);
		if(u==v)continue;
		G[u].push_back(v);
		cnt[v]++;
	}
	queue<int>P;
	int vc=0;
	for(int i=0;i<N;i++)if(uf.find(i)==i)
	{
		vc++;
		if(cnt[i]==0)P.push(i);
	}
	int pc=0;
	while(!P.empty())
	{
		pc++;
		int u=P.front();P.pop();
		for(int v:G[u])if(--cnt[v]==0)P.push(v);
	}
	cout<<(vc==pc?"No":"Yes")<<endl;
}
0