結果
| 問題 |
No.1420 国勢調査 (Easy)
|
| コンテスト | |
| ユーザー |
Haa
|
| 提出日時 | 2021-03-05 22:09:45 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 256 ms / 2,000 ms |
| コード長 | 1,068 bytes |
| コンパイル時間 | 2,101 ms |
| コンパイル使用メモリ | 177,964 KB |
| 実行使用メモリ | 13,696 KB |
| 最終ジャッジ日時 | 2024-10-07 02:10:05 |
| 合計ジャッジ時間 | 7,933 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 30 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) v.begin(),v.end()
constexpr ll MOD=1000000007;
constexpr ll INF=2e18;
vector<vector<P>> edge(110000,vector<P>(0));
vector<bool> used(110000,0);
VI ans(110000,-1);
bool no=0;
void dfs(int v, int x){
for(auto to:edge[v]){
if(ans[to.first]!=-1&&ans[to.first]!=(x^to.second))
no=1;
if(!used[to.first]){
ans[to.first]=x^to.second;
used[to.first]=1;
dfs(to.first,x^to.second);
}
}
}
int main(){
int n, m; cin >> n >> m;
int a, b, y;
REP(i,m){
cin >> a >> b >> y;
a--, b--;
edge[a].push_back({b,y});
edge[b].push_back({a,y});
}
REP(i,n){
if(!used[i]){
ans[i]=0;
dfs(i,0);
}
}
if(no)
cout << -1 << endl;
else{
REP(i,n)
cout << ans[i] << endl;
}
return 0;
}
Haa