結果

問題 No.1420 国勢調査 (Easy)
ユーザー たたき@競プロたたき@競プロ
提出日時 2023-09-06 15:12:51
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 161 ms / 2,000 ms
コード長 904 bytes
コンパイル時間 5,639 ms
コンパイル使用メモリ 312,844 KB
実行使用メモリ 12,792 KB
最終ジャッジ日時 2023-09-06 15:13:05
合計ジャッジ時間 13,221 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 100 ms
9,184 KB
testcase_03 AC 101 ms
9,080 KB
testcase_04 AC 105 ms
9,060 KB
testcase_05 AC 100 ms
9,208 KB
testcase_06 AC 100 ms
9,072 KB
testcase_07 AC 95 ms
9,184 KB
testcase_08 AC 101 ms
9,104 KB
testcase_09 AC 100 ms
9,080 KB
testcase_10 AC 99 ms
9,096 KB
testcase_11 AC 101 ms
9,204 KB
testcase_12 AC 17 ms
6,736 KB
testcase_13 AC 26 ms
6,732 KB
testcase_14 AC 15 ms
6,660 KB
testcase_15 AC 26 ms
6,848 KB
testcase_16 AC 25 ms
6,760 KB
testcase_17 AC 25 ms
6,724 KB
testcase_18 AC 26 ms
6,756 KB
testcase_19 AC 24 ms
6,976 KB
testcase_20 AC 26 ms
6,780 KB
testcase_21 AC 24 ms
6,696 KB
testcase_22 AC 146 ms
12,544 KB
testcase_23 AC 149 ms
12,536 KB
testcase_24 AC 161 ms
12,792 KB
testcase_25 AC 147 ms
12,592 KB
testcase_26 AC 147 ms
12,564 KB
testcase_27 AC 140 ms
12,568 KB
testcase_28 AC 136 ms
12,532 KB
testcase_29 AC 135 ms
12,576 KB
testcase_30 AC 151 ms
12,568 KB
testcase_31 AC 134 ms
12,428 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
  
    
0