結果

問題 No.1420 国勢調査 (Easy)
ユーザー gorugo30gorugo30
提出日時 2021-03-06 09:58:29
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,859 bytes
コンパイル時間 4,171 ms
コンパイル使用メモリ 227,776 KB
実行使用メモリ 27,840 KB
最終ジャッジ日時 2024-04-16 22:30:11
合計ジャッジ時間 19,100 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 59 ms
5,632 KB
testcase_08 AC 112 ms
5,760 KB
testcase_09 AC 68 ms
5,632 KB
testcase_10 AC 115 ms
5,888 KB
testcase_11 AC 34 ms
5,760 KB
testcase_12 AC 41 ms
27,520 KB
testcase_13 WA -
testcase_14 AC 49 ms
27,648 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 246 ms
27,520 KB
testcase_28 AC 280 ms
27,520 KB
testcase_29 AC 123 ms
27,520 KB
testcase_30 AC 261 ms
27,520 KB
testcase_31 AC 254 ms
27,520 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;

#define MOD 1000000007
#define MOD9 998244353
#define pb push_back
#define yes "Yes"
#define no "No"
#define takah "Takahashi"
#define aoki "Aoki"
#define ALL(x) (x).begin(), (x).end()
template<class T> bool chmax(T &x, const T &y){if (x < y) {x = y; return true;} return false;}
template<class T> bool chmin(T &x, const T &y){if (x > y) {x = y; return true;} return false;}
template<class T> void print(T x){cout << x << endl;}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    int N, M;
    cin >> N >> M;
    vector<dsu> ufts(30, dsu(2 * N));
    
    int A, B, Y;
    for (int hito = 0; hito < M; hito++){
        cin >> A >> B >> Y;
        A--; B--;
        for (int i = 0; i < 30; i++){
            if (Y & 1){
                if (ufts[i].same(A, B)){
                    print(-1);
                    return 0;
                }
                ufts[i].merge(A, B + N);
                ufts[i].merge(A + N, B);
            } else {
                if (ufts[i].same(A + N, B)){
                    print(-1);
                    return 0;
                }
                ufts[i].merge(A, B);
                ufts[i].merge(B, A);
            }
            Y >>= 1;
        }
    }
    int pow2 = 1;
    vector<int> X(N, 0);
    for (int k = 0; k < 30; k++){
        vector<int> x(N, 0);
        for (int i = 0; i < N; i++){
            if (ufts[k].size(i) == 1) continue;
            int r = ufts[k].leader(i);
            if (r < N){
                x[i] = x[r];
                X[i] += pow2 * x[r];
            } else {
                r -= N;
                x[i] = 1 ^ x[r];
                X[i] += pow2 * (1 ^ x[r]);
            }
        }
        pow2 *= 2;
    }
    for (int i = 0; i < N; i++){
        print(X[i]);
    }
}
0