結果

問題 No.1420 国勢調査 (Easy)
ユーザー kotatsugamekotatsugame
提出日時 2021-03-11 02:21:04
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 248 ms / 2,000 ms
コード長 725 bytes
コンパイル時間 867 ms
コンパイル使用メモリ 77,824 KB
実行使用メモリ 10,752 KB
最終ジャッジ日時 2024-04-20 19:32:46
合計ジャッジ時間 7,906 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,528 KB
testcase_01 AC 3 ms
6,656 KB
testcase_02 AC 108 ms
9,344 KB
testcase_03 AC 112 ms
9,472 KB
testcase_04 AC 111 ms
9,472 KB
testcase_05 AC 110 ms
9,344 KB
testcase_06 AC 111 ms
9,344 KB
testcase_07 AC 99 ms
9,472 KB
testcase_08 AC 96 ms
9,472 KB
testcase_09 AC 98 ms
9,344 KB
testcase_10 AC 96 ms
9,600 KB
testcase_11 AC 98 ms
9,472 KB
testcase_12 AC 15 ms
7,680 KB
testcase_13 AC 137 ms
7,552 KB
testcase_14 AC 15 ms
7,552 KB
testcase_15 AC 142 ms
7,680 KB
testcase_16 AC 133 ms
7,552 KB
testcase_17 AC 138 ms
7,552 KB
testcase_18 AC 139 ms
7,680 KB
testcase_19 AC 141 ms
7,680 KB
testcase_20 AC 138 ms
7,680 KB
testcase_21 AC 139 ms
7,680 KB
testcase_22 AC 241 ms
10,752 KB
testcase_23 AC 241 ms
10,624 KB
testcase_24 AC 248 ms
10,624 KB
testcase_25 AC 241 ms
10,752 KB
testcase_26 AC 244 ms
10,624 KB
testcase_27 AC 113 ms
10,624 KB
testcase_28 AC 123 ms
10,496 KB
testcase_29 AC 115 ms
10,624 KB
testcase_30 AC 113 ms
10,624 KB
testcase_31 AC 111 ms
10,624 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:9:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    9 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
#include<vector>
#include<queue>
using namespace std;
int N,M;
vector<pair<int,int> >G[1<<17];
bool vis[1<<17];
int X[1<<17];
main()
{
	cin>>N>>M;
	for(int i=0;i<M;i++)
	{
		int a,b,y;cin>>a>>b>>y;
		a--,b--;
		G[a].push_back(make_pair(b,y));
		G[b].push_back(make_pair(a,y));
	}
	for(int i=0;i<N;i++)if(!vis[i])
	{
		vis[i]=true;
		queue<int>P;
		P.push(i);
		while(!P.empty())
		{
			int u=P.front();P.pop();
			for(pair<int,int>e:G[u])
			{
				int v=e.first;
				if(vis[v])
				{
					if(X[v]!=(X[u]^e.second))
					{
						cout<<-1<<endl;
						return 0;
					}
				}
				else
				{
					vis[v]=true;
					P.push(v);
					X[v]=X[u]^e.second;
				}
			}
		}
	}
	for(int i=0;i<N;i++)cout<<X[i]<<endl;
}
0