結果

問題 No.1420 国勢調査 (Easy)
ユーザー KKT89KKT89
提出日時 2021-03-05 21:58:38
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 82 ms / 2,000 ms
コード長 943 bytes
コンパイル時間 2,248 ms
コンパイル使用メモリ 206,852 KB
実行使用メモリ 9,940 KB
最終ジャッジ日時 2024-04-16 09:27:27
合計ジャッジ時間 5,897 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 43 ms
6,944 KB
testcase_03 AC 43 ms
6,948 KB
testcase_04 AC 44 ms
6,940 KB
testcase_05 AC 44 ms
6,940 KB
testcase_06 AC 45 ms
6,940 KB
testcase_07 AC 42 ms
6,940 KB
testcase_08 AC 41 ms
6,940 KB
testcase_09 AC 42 ms
6,940 KB
testcase_10 AC 42 ms
6,944 KB
testcase_11 AC 42 ms
6,948 KB
testcase_12 AC 9 ms
6,944 KB
testcase_13 AC 21 ms
6,944 KB
testcase_14 AC 10 ms
6,944 KB
testcase_15 AC 19 ms
6,940 KB
testcase_16 AC 20 ms
6,940 KB
testcase_17 AC 20 ms
6,940 KB
testcase_18 AC 19 ms
6,944 KB
testcase_19 AC 20 ms
6,944 KB
testcase_20 AC 20 ms
6,944 KB
testcase_21 AC 19 ms
6,940 KB
testcase_22 AC 76 ms
9,700 KB
testcase_23 AC 81 ms
9,728 KB
testcase_24 AC 79 ms
9,940 KB
testcase_25 AC 79 ms
9,728 KB
testcase_26 AC 82 ms
9,856 KB
testcase_27 AC 64 ms
9,472 KB
testcase_28 AC 65 ms
9,600 KB
testcase_29 AC 64 ms
9,472 KB
testcase_30 AC 61 ms
9,600 KB
testcase_31 AC 62 ms
9,444 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
    return (ull)rng() % B;
}

constexpr ll mod=1e9+7;

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n,m; cin >> n >> m;
	vector<vector<pair<int,int>>> v(n);
	for(int i=0;i<m;i++){
		int a,b,y; cin >> a >> b >> y;
		a--; b--;
		v[a].push_back({b,y});
		v[b].push_back({a,y});
	}
	vector<int> res(n,-1);
	queue<int> q;
	for(int i=0;i<n;i++){
		if(res[i]==-1){
			res[i]=0;
			q.push(i);
			while(q.size()){
				int p=q.front();
				q.pop();
				for(auto t:v[p]){
					if(res[t.first]==-1){
						res[t.first]=res[p]^t.second;
						q.push(t.first);
					}
					else{
						if(res[t.first]!=(res[p]^t.second)){
							printf("-1\n"); return 0;
						}
					}
				}
			}
		}
	}
	for(int i=0;i<n;i++){
		printf("%d\n",res[i]);
	}
}
0