結果

問題 No.2277 Honest or Dishonest ?
ユーザー MarioYCMarioYC
提出日時 2023-04-21 22:34:02
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,097 bytes
コンパイル時間 1,905 ms
コンパイル使用メモリ 194,732 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-25 19:02:58
合計ジャッジ時間 5,814 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 19 ms
6,940 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 14 ms
6,944 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 16 ms
6,944 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 63 ms
6,944 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 8 ms
6,944 KB
testcase_27 AC 31 ms
6,940 KB
testcase_28 AC 18 ms
6,944 KB
testcase_29 WA -
testcase_30 AC 30 ms
6,940 KB
testcase_31 AC 50 ms
6,940 KB
testcase_32 AC 26 ms
6,944 KB
testcase_33 WA -
testcase_34 AC 66 ms
6,940 KB
testcase_35 AC 6 ms
6,940 KB
testcase_36 AC 41 ms
6,944 KB
testcase_37 AC 67 ms
6,940 KB
testcase_38 AC 17 ms
6,944 KB
testcase_39 AC 22 ms
6,944 KB
testcase_40 AC 7 ms
6,944 KB
testcase_41 AC 72 ms
6,940 KB
testcase_42 AC 50 ms
6,944 KB
testcase_43 AC 73 ms
6,944 KB
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 AC 71 ms
6,944 KB
testcase_50 AC 71 ms
6,940 KB
testcase_51 AC 73 ms
6,948 KB
testcase_52 AC 72 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

const int maxn = 100005;
const int mod = 998244353;
int a[maxn],b[maxn],c[maxn];

int parent[maxn],dist[maxn];

int Find(int x){
    if(parent[x] != x){
        parent[x] = Find(parent[x]);
        dist[x] ^= dist[ parent[x] ];
    }
    return parent[x];
}

int comp;

bool Union(int x, int y, int c){
    int rx = Find(x);
    int ry = Find(y);
    if(rx != ry){
        --comp;
        dist[ry] = (dist[x] ^ dist[y] ^ c);
        parent[ry] = rx;
        return true;
    }
    bool ok = (dist[y] ^ dist[x]) == c;
    return ok;
}

int main(){
    int N,Q;
    cin >> N >> Q;
    for(int i = 0;i < Q;++i){
        cin >> a[i] >> b[i] >> c[i];
    }
    for(int i = 1;i <= N;++i){
        parent[i] = i;
        dist[i] = 0;
    }
    comp = N;
    ll ans = 1;
    for(int i = 0;i < Q;++i){
        if(!Union(a[i], b[i], c[i])){
            ans = 0;
            break;
        }
    }
    if(ans){
        for(int i = 1;i <= comp;++i){
            ans = ans * 2 % mod;
        }
    }
    cout << ans << endl;
    return 0;
}
0