結果

問題 No.1420 国勢調査 (Easy)
ユーザー publflpublfl
提出日時 2021-03-05 22:51:25
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 98 ms / 2,000 ms
コード長 806 bytes
コンパイル時間 388 ms
コンパイル使用メモリ 51,328 KB
実行使用メモリ 12,032 KB
最終ジャッジ日時 2024-04-16 10:43:16
合計ジャッジ時間 4,263 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
6,144 KB
testcase_01 AC 4 ms
6,016 KB
testcase_02 AC 46 ms
9,600 KB
testcase_03 AC 46 ms
9,600 KB
testcase_04 AC 48 ms
9,600 KB
testcase_05 AC 46 ms
9,600 KB
testcase_06 AC 47 ms
9,600 KB
testcase_07 AC 45 ms
9,600 KB
testcase_08 AC 45 ms
9,600 KB
testcase_09 AC 46 ms
9,600 KB
testcase_10 AC 45 ms
9,600 KB
testcase_11 AC 46 ms
9,600 KB
testcase_12 AC 12 ms
6,912 KB
testcase_13 AC 20 ms
7,040 KB
testcase_14 AC 11 ms
6,912 KB
testcase_15 AC 20 ms
6,912 KB
testcase_16 AC 20 ms
6,912 KB
testcase_17 AC 20 ms
6,912 KB
testcase_18 AC 20 ms
7,040 KB
testcase_19 AC 20 ms
7,040 KB
testcase_20 AC 20 ms
7,040 KB
testcase_21 AC 21 ms
7,168 KB
testcase_22 AC 98 ms
12,032 KB
testcase_23 AC 91 ms
11,904 KB
testcase_24 AC 90 ms
12,032 KB
testcase_25 AC 95 ms
11,904 KB
testcase_26 AC 90 ms
12,032 KB
testcase_27 AC 76 ms
12,032 KB
testcase_28 AC 74 ms
12,032 KB
testcase_29 AC 79 ms
11,904 KB
testcase_30 AC 80 ms
12,032 KB
testcase_31 AC 75 ms
12,032 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <vector>

std::vector< std::pair<int,int> > V[100010];
int check[100010];
void func(int k, int prev, int C)
{
	check[k] = C;
	for(int i=0;i<V[k].size();i++)
	{
		if(V[k][i].first==prev) continue;
		if(check[V[k][i].first]==-1) func(V[k][i].first,k,C^V[k][i].second);
	}
}
int main()
{
	int a,b;
	scanf("%d%d",&a,&b);
	for(int i=1;i<=b;i++)
	{
		int c,d,e;
		scanf("%d%d%d",&c,&d,&e);
		V[c].push_back(std::make_pair(d,e));
		V[d].push_back(std::make_pair(c,e));
	}
	
	for(int i=1;i<=a;i++) check[i] = -1;
	for(int i=1;i<=a;i++) if(check[i]==-1) func(i,0,0);
	
	for(int i=1;i<=a;i++)
	{
		for(int j=0;j<V[i].size();j++)
		{
			if((check[i]^check[V[i][j].first])!=V[i][j].second)
			{
				printf("-1");
				return 0;
			}
		}
	}
	
	for(int i=1;i<=a;i++) printf("%d\n",check[i]);
}
0