結果

問題 No.1420 国勢調査 (Easy)
ユーザー milanis48663220milanis48663220
提出日時 2021-03-05 22:36:31
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 212 ms / 2,000 ms
コード長 1,543 bytes
コンパイル時間 950 ms
コンパイル使用メモリ 96,736 KB
実行使用メモリ 11,136 KB
最終ジャッジ日時 2024-04-16 10:22:38
合計ジャッジ時間 6,515 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
6,016 KB
testcase_01 AC 4 ms
5,760 KB
testcase_02 AC 59 ms
9,088 KB
testcase_03 AC 59 ms
8,960 KB
testcase_04 AC 58 ms
9,216 KB
testcase_05 AC 60 ms
9,088 KB
testcase_06 AC 60 ms
9,088 KB
testcase_07 AC 44 ms
8,960 KB
testcase_08 AC 44 ms
8,984 KB
testcase_09 AC 44 ms
9,088 KB
testcase_10 AC 44 ms
9,088 KB
testcase_11 AC 44 ms
8,704 KB
testcase_12 AC 10 ms
6,784 KB
testcase_13 AC 134 ms
6,784 KB
testcase_14 AC 9 ms
6,944 KB
testcase_15 AC 137 ms
6,944 KB
testcase_16 AC 136 ms
6,912 KB
testcase_17 AC 138 ms
6,912 KB
testcase_18 AC 137 ms
6,944 KB
testcase_19 AC 138 ms
6,784 KB
testcase_20 AC 141 ms
7,040 KB
testcase_21 AC 137 ms
6,784 KB
testcase_22 AC 212 ms
10,880 KB
testcase_23 AC 204 ms
10,880 KB
testcase_24 AC 205 ms
11,008 KB
testcase_25 AC 206 ms
10,880 KB
testcase_26 AC 205 ms
11,136 KB
testcase_27 AC 65 ms
9,856 KB
testcase_28 AC 64 ms
9,796 KB
testcase_29 AC 64 ms
9,976 KB
testcase_30 AC 65 ms
9,600 KB
testcase_31 AC 68 ms
9,600 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cassert>

#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using namespace std;
typedef long long ll;
bool used[100000];

struct edge{
    int to, y;
};

vector<edge> g[100000];
int ans[100000];

bool dfs(int v, int x){
    used[v] = true;
    ans[v] = x;
    for(edge e : g[v]){
        if(!used[e.to]){
            if(!dfs(e.to, x^e.y)) return false;
        }else{
            if(ans[e.to] != (x^e.y)) return false;
        }
    }
    return true;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int n, m; cin >> n >> m;
    for(int i = 0; i < m; i++){
        int a, b, y; cin >> a >> b >> y; a--; b--;
        g[a].push_back(edge{b, y});
        g[b].push_back(edge{a, y});
    }
    for(int i = 0; i < n; i++){
        if(!used[i]){
            if(!dfs(i, 0)){
                cout << -1 << endl;
                return 0;
            }
        }
    }
    
    for(int v = 0; v < n; v++){
        for(edge e : g[v]) assert(ans[v]^ans[e.to] == e.y);
    }
    for(int i = 0; i < n; i++) cout << ans[i] << endl;
}
0