結果

問題 No.1420 国勢調査 (Easy)
ユーザー milanis48663220milanis48663220
提出日時 2021-03-05 22:34:57
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,445 bytes
コンパイル時間 1,198 ms
コンパイル使用メモリ 96,124 KB
実行使用メモリ 11,136 KB
最終ジャッジ日時 2024-04-16 10:20:27
合計ジャッジ時間 7,282 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,016 KB
testcase_01 AC 3 ms
5,888 KB
testcase_02 AC 56 ms
9,156 KB
testcase_03 AC 56 ms
8,960 KB
testcase_04 AC 60 ms
9,216 KB
testcase_05 AC 58 ms
9,088 KB
testcase_06 AC 58 ms
9,216 KB
testcase_07 AC 43 ms
9,088 KB
testcase_08 AC 42 ms
9,060 KB
testcase_09 AC 43 ms
9,216 KB
testcase_10 AC 42 ms
9,156 KB
testcase_11 AC 43 ms
8,832 KB
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 AC 57 ms
9,856 KB
testcase_28 AC 55 ms
9,728 KB
testcase_29 AC 62 ms
9,856 KB
testcase_30 AC 57 ms
9,856 KB
testcase_31 AC 55 ms
9,496 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});
    }
    if(!dfs(0, 0)){
        cout << -1 << endl;
    }else{
        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