結果

問題 No.1640 簡単な色塗り
ユーザー kotatsugamekotatsugame
提出日時 2021-08-06 21:44:23
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 242 ms / 2,000 ms
コード長 921 bytes
コンパイル時間 1,056 ms
コンパイル使用メモリ 82,900 KB
実行使用メモリ 17,048 KB
最終ジャッジ日時 2023-09-12 01:48:31
合計ジャッジ時間 13,235 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
9,780 KB
testcase_01 AC 5 ms
9,508 KB
testcase_02 AC 5 ms
9,508 KB
testcase_03 AC 5 ms
9,604 KB
testcase_04 AC 191 ms
14,264 KB
testcase_05 AC 200 ms
17,048 KB
testcase_06 AC 5 ms
9,516 KB
testcase_07 AC 5 ms
9,516 KB
testcase_08 AC 4 ms
9,812 KB
testcase_09 AC 5 ms
9,552 KB
testcase_10 AC 130 ms
12,668 KB
testcase_11 AC 109 ms
12,240 KB
testcase_12 AC 94 ms
11,704 KB
testcase_13 AC 208 ms
14,564 KB
testcase_14 AC 203 ms
14,704 KB
testcase_15 AC 69 ms
11,352 KB
testcase_16 AC 84 ms
11,524 KB
testcase_17 AC 167 ms
13,592 KB
testcase_18 AC 19 ms
9,924 KB
testcase_19 AC 96 ms
11,956 KB
testcase_20 AC 124 ms
12,664 KB
testcase_21 AC 105 ms
11,868 KB
testcase_22 AC 15 ms
9,808 KB
testcase_23 AC 138 ms
12,912 KB
testcase_24 AC 41 ms
10,720 KB
testcase_25 AC 98 ms
11,872 KB
testcase_26 AC 151 ms
13,272 KB
testcase_27 AC 67 ms
11,260 KB
testcase_28 AC 191 ms
14,160 KB
testcase_29 AC 151 ms
13,540 KB
testcase_30 AC 15 ms
10,404 KB
testcase_31 AC 94 ms
15,832 KB
testcase_32 AC 81 ms
14,732 KB
testcase_33 AC 54 ms
12,760 KB
testcase_34 AC 47 ms
11,204 KB
testcase_35 AC 37 ms
10,432 KB
testcase_36 AC 14 ms
10,124 KB
testcase_37 AC 16 ms
10,088 KB
testcase_38 AC 55 ms
11,388 KB
testcase_39 AC 36 ms
12,104 KB
testcase_40 AC 30 ms
10,736 KB
testcase_41 AC 59 ms
12,936 KB
testcase_42 AC 41 ms
11,936 KB
testcase_43 AC 31 ms
10,432 KB
testcase_44 AC 39 ms
11,820 KB
testcase_45 AC 24 ms
10,212 KB
testcase_46 AC 14 ms
10,060 KB
testcase_47 AC 12 ms
10,244 KB
testcase_48 AC 56 ms
11,480 KB
testcase_49 AC 8 ms
9,740 KB
testcase_50 AC 5 ms
9,584 KB
testcase_51 AC 5 ms
9,672 KB
testcase_52 AC 235 ms
15,892 KB
testcase_53 AC 242 ms
15,928 KB
07_evil_01.txt RE -
07_evil_02.txt RE -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:22:1: 警告: ISO C++ では型の無い ‘main’ の宣言を禁止しています [-Wreturn-type]
   22 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
#include<vector>
#include<atcoder/dsu>
using namespace std;
int N;
int A[1<<17],B[1<<17];
int ans[1<<17];
vector<int>E[1<<17];
vector<pair<int,int> >G[1<<17];
void dfs(int u,int p)
{
	for(pair<int,int>e:G[u])
	{
		int v=e.first;
		if(v!=p)
		{
			ans[e.second]=v;
			dfs(v,u);
		}
	}
}
main()
{
	cin>>N;
	atcoder::dsu P(N);
	for(int i=0;i<N;i++)
	{
		cin>>A[i]>>B[i];
		A[i]--,B[i]--;
		P.merge(A[i],B[i]);
	}
	for(int i=0;i<N;i++)
	{
		int p=P.leader(A[i]);
		E[p].push_back(i);
	}
	atcoder::dsu Q(N);
	for(int i=0;i<N;i++)if(i==P.leader(i))
	{
		int fi=-1;
		for(int ei:E[i])
		{
			int a=A[ei],b=B[ei];
			if(Q.same(a,b))fi=ei;
			else
			{
				G[a].push_back(make_pair(b,ei));
				G[b].push_back(make_pair(a,ei));
				Q.merge(a,b);
			}
		}
		if(fi==-1)
		{
			cout<<"No"<<endl;
			return 0;
		}
		dfs(A[fi],-1);
		ans[fi]=A[fi];
	}
	cout<<"Yes"<<endl;
	for(int i=0;i<N;i++)cout<<ans[i]+1<<endl;
}
0