結果
問題 | No.1420 国勢調査 (Easy) |
ユーザー |
|
提出日時 | 2021-03-05 21:58:38 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 66 ms / 2,000 ms |
コード長 | 943 bytes |
コンパイル時間 | 2,188 ms |
コンパイル使用メモリ | 203,516 KB |
最終ジャッジ日時 | 2025-01-19 11:03:39 |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 30 |
ソースコード
#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]); } }