結果
| 問題 | No.1420 国勢調査 (Easy) | 
| コンテスト | |
| ユーザー |  たたき@競プロ | 
| 提出日時 | 2023-09-06 15:12:51 | 
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 187 ms / 2,000 ms | 
| コード長 | 904 bytes | 
| コンパイル時間 | 6,431 ms | 
| コンパイル使用メモリ | 314,528 KB | 
| 実行使用メモリ | 12,928 KB | 
| 最終ジャッジ日時 | 2024-06-24 09:37:15 | 
| 合計ジャッジ時間 | 13,557 ms | 
| ジャッジサーバーID (参考情報) | judge3 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 30 | 
ソースコード
#include<bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
using mint=modint998244353; //1000000007;
using ll=long long;
using pp=pair<ll,ll>;
#define sr string 
#define vc vector
#define fi first
#define se second
#define rep(i,n) for(ll i=0;i<(ll)n;i++)
#define pb push_back
#define all(v) v.begin(),v.end()
#define pque priority_queue
#define bpc(a) __builtin_popcount(a)
int main(){
  int n,m;cin>>n>>m;
  vc v(n,vc<pp>(0));
  rep(i,m){
    int a,b,c;cin>>a>>b>>c;
    a--;b--; 
    v[a].pb({b,c}); v[b].pb({a,c});
  }
  vc<int>x(n,0),bo(n,0); bool ans=true;
  auto f=[&](auto f,int a)->void{
    bo[a]=1;
    for(auto [au,c]:v[a]){
      int nc=x[a]^c;
      if(bo[au]&&nc!=x[au])ans=false;
      if(!bo[au]){
        x[au]=nc;
        f(f,au);
      }
    }
    return;
  };
  rep(i,n)if(!bo[i])f(f,i);
  if(ans)rep(i,n)cout<<x[i]<<"\n";
  else cout<<-1;
}
  
    
            
            
            
        