結果

問題 No.1420 国勢調査 (Easy)
ユーザー chocoruskchocorusk
提出日時 2021-03-05 22:00:53
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 277 ms / 2,000 ms
コード長 1,365 bytes
コンパイル時間 4,238 ms
コンパイル使用メモリ 189,752 KB
実行使用メモリ 11,924 KB
最終ジャッジ日時 2023-07-29 01:44:29
合計ジャッジ時間 11,283 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,720 KB
testcase_01 AC 4 ms
5,772 KB
testcase_02 AC 116 ms
9,916 KB
testcase_03 AC 114 ms
9,988 KB
testcase_04 AC 116 ms
10,032 KB
testcase_05 AC 114 ms
10,112 KB
testcase_06 AC 114 ms
9,940 KB
testcase_07 AC 104 ms
10,172 KB
testcase_08 AC 100 ms
10,016 KB
testcase_09 AC 101 ms
10,028 KB
testcase_10 AC 101 ms
10,168 KB
testcase_11 AC 102 ms
9,972 KB
testcase_12 AC 16 ms
7,052 KB
testcase_13 AC 144 ms
6,940 KB
testcase_14 AC 17 ms
7,124 KB
testcase_15 AC 145 ms
6,992 KB
testcase_16 AC 147 ms
6,940 KB
testcase_17 AC 145 ms
6,928 KB
testcase_18 AC 145 ms
6,972 KB
testcase_19 AC 146 ms
7,052 KB
testcase_20 AC 147 ms
6,980 KB
testcase_21 AC 149 ms
6,888 KB
testcase_22 AC 275 ms
11,788 KB
testcase_23 AC 277 ms
11,800 KB
testcase_24 AC 274 ms
11,836 KB
testcase_25 AC 274 ms
11,732 KB
testcase_26 AC 274 ms
11,924 KB
testcase_27 AC 141 ms
11,724 KB
testcase_28 AC 141 ms
11,840 KB
testcase_29 AC 140 ms
11,848 KB
testcase_30 AC 142 ms
11,732 KB
testcase_31 AC 140 ms
11,792 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#include <list>
#include <atcoder/all>
#define popcount __builtin_popcount
using namespace std;
using namespace atcoder;
typedef long long ll;
typedef pair<int, int> P;
int n, m;
vector<P> g[100010];
int y[100010];
int a[100010], b[100010];
bool used[100010];
int ans[100010];
bool dame;
void dfs(int x){
    used[x]=1;
    for(auto p:g[x]){
        int z=p.first;
        int i=p.second;
        if(!used[z]){
            ans[z]=(y[i]^ans[x]);
            dfs(z);
        }else if(ans[z]!=(y[i]^ans[x])){
            dame=1;
        }
    }
}
int main()
{
    cin>>n>>m;
    for(int i=0; i<m; i++){
        cin>>a[i]>>b[i]>>y[i];
        a[i]--; b[i]--;
        g[a[i]].push_back({b[i], i});
        g[b[i]].push_back({a[i], i});
    }
    for(int i=0; i<n; i++){
        if(!used[i]){
            dfs(i);
        }
    }
    if(dame) cout<<-1<<endl;
    else{
        for(int i=0; i<n; i++) cout<<ans[i]<<endl;
    }
    return 0;
}
0