結果

問題 No.2277 Honest or Dishonest ?
ユーザー MarioYCMarioYC
提出日時 2023-04-22 06:54:48
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 79 ms / 2,000 ms
コード長 1,088 bytes
コンパイル時間 2,189 ms
コンパイル使用メモリ 195,104 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-25 19:13:12
合計ジャッジ時間 5,698 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 1 ms
6,812 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 64 ms
6,944 KB
testcase_04 AC 65 ms
6,944 KB
testcase_05 AC 18 ms
6,944 KB
testcase_06 AC 57 ms
6,940 KB
testcase_07 AC 43 ms
6,940 KB
testcase_08 AC 12 ms
6,944 KB
testcase_09 AC 36 ms
6,944 KB
testcase_10 AC 34 ms
6,940 KB
testcase_11 AC 17 ms
6,944 KB
testcase_12 AC 33 ms
6,940 KB
testcase_13 AC 66 ms
6,940 KB
testcase_14 AC 40 ms
6,940 KB
testcase_15 AC 16 ms
6,944 KB
testcase_16 AC 46 ms
6,940 KB
testcase_17 AC 22 ms
6,940 KB
testcase_18 AC 55 ms
6,940 KB
testcase_19 AC 55 ms
6,944 KB
testcase_20 AC 46 ms
6,940 KB
testcase_21 AC 47 ms
6,944 KB
testcase_22 AC 39 ms
6,940 KB
testcase_23 AC 65 ms
6,940 KB
testcase_24 AC 35 ms
6,940 KB
testcase_25 AC 39 ms
6,944 KB
testcase_26 AC 8 ms
6,944 KB
testcase_27 AC 30 ms
6,940 KB
testcase_28 AC 16 ms
6,940 KB
testcase_29 AC 26 ms
6,944 KB
testcase_30 AC 29 ms
6,940 KB
testcase_31 AC 48 ms
6,944 KB
testcase_32 AC 25 ms
6,944 KB
testcase_33 AC 60 ms
6,944 KB
testcase_34 AC 68 ms
6,944 KB
testcase_35 AC 5 ms
6,944 KB
testcase_36 AC 42 ms
6,944 KB
testcase_37 AC 67 ms
6,940 KB
testcase_38 AC 16 ms
6,944 KB
testcase_39 AC 22 ms
6,940 KB
testcase_40 AC 6 ms
6,944 KB
testcase_41 AC 71 ms
6,940 KB
testcase_42 AC 49 ms
6,944 KB
testcase_43 AC 75 ms
6,944 KB
testcase_44 AC 76 ms
6,940 KB
testcase_45 AC 77 ms
6,940 KB
testcase_46 AC 73 ms
6,940 KB
testcase_47 AC 75 ms
6,940 KB
testcase_48 AC 76 ms
6,944 KB
testcase_49 AC 79 ms
6,940 KB
testcase_50 AC 75 ms
6,944 KB
testcase_51 AC 72 ms
6,940 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){
        int p = parent[x];
        parent[x] = Find(p);
        dist[x] ^= dist[p];
    }
    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])){
            cout << 0 << endl;
            return 0;
        }
    }
    for(int i = 1;i <= comp;++i){
        ans = ans * 2 % mod;
    }
    cout << ans << endl;
    return 0;
}
0