結果

問題 No.1420 国勢調査 (Easy)
ユーザー srjywrdnprktsrjywrdnprkt
提出日時 2023-06-19 20:35:26
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,381 bytes
コンパイル時間 2,250 ms
コンパイル使用メモリ 214,136 KB
実行使用メモリ 179,756 KB
最終ジャッジ日時 2023-09-09 15:46:54
合計ジャッジ時間 26,649 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 792 ms
86,228 KB
testcase_03 AC 819 ms
86,556 KB
testcase_04 AC 803 ms
86,356 KB
testcase_05 AC 827 ms
86,428 KB
testcase_06 AC 822 ms
86,552 KB
testcase_07 AC 660 ms
86,716 KB
testcase_08 AC 653 ms
86,996 KB
testcase_09 AC 635 ms
86,780 KB
testcase_10 AC 622 ms
86,676 KB
testcase_11 AC 627 ms
86,608 KB
testcase_12 AC 158 ms
91,532 KB
testcase_13 AC 466 ms
91,424 KB
testcase_14 AC 159 ms
91,732 KB
testcase_15 AC 465 ms
91,296 KB
testcase_16 AC 467 ms
91,568 KB
testcase_17 AC 468 ms
91,420 KB
testcase_18 AC 461 ms
90,968 KB
testcase_19 AC 459 ms
91,236 KB
testcase_20 AC 469 ms
91,564 KB
testcase_21 AC 463 ms
91,052 KB
testcase_22 TLE -
testcase_23 TLE -
testcase_24 TLE -
testcase_25 TLE -
testcase_26 TLE -
testcase_27 AC 1,190 ms
178,296 KB
testcase_28 AC 1,174 ms
178,272 KB
testcase_29 AC 1,175 ms
178,564 KB
testcase_30 AC 1,179 ms
178,680 KB
testcase_31 AC 1,177 ms
178,680 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

vector<bool> vst;
vector<int> bt;

void dfs(vector<vector<pair<int, int>>> &E, int from){
    vst[from] = 1;
    int alt;

    for(auto [to, C] : E[from]){
        if (C == 1) alt = 1-bt[from];
        else alt=bt[from];
        if (vst[to]){
            if (alt != bt[to]){
                cout << -1 << endl;
                exit(0);
            }
            continue;
        }
        bt[to] = alt;
        dfs(E, to);
    }
}

int main(){

    int N, M, A, B, Y;
    cin >> N >> M;
    vector<int> ans(N);
    vector<vector<vector<pair<int, int>>>> E(30, vector<vector<pair<int, int>>>(N));

    for (int i=0; i<M; i++){
        cin >> A >> B >> Y; A--; B--;
        for (int j=0; j<30; j++){
            if (Y & 1<<j){
                E[j][A].push_back({B, 1});
                E[j][B].push_back({A, 1});
            }
            else{
                E[j][A].push_back({B, 0});
                E[j][B].push_back({A, 0});
            }
        }
    }
    vst.resize(N);
    bt.resize(N);


    for (int i=0; i<30; i++){
        for (int j=0; j<N; j++){
            vst[j] = 0;
            bt[j] = 0;
        }
        for (int j=0; j<N; j++){
            if (!vst[j]) dfs(E[i], j);
        }
        for (int j=0; j<N; j++) ans[j] += bt[j]*(1<<i);
    }

    for (int i=0; i<N; i++) cout << ans[i] << endl;

    return 0;
}
0