結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 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 18 ms
6,940 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 13 ms
6,940 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,940 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 66 ms
6,940 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 8 ms
6,940 KB
testcase_27 AC 30 ms
6,940 KB
testcase_28 AC 17 ms
6,940 KB
testcase_29 WA -
testcase_30 AC 27 ms
6,944 KB
testcase_31 AC 47 ms
6,940 KB
testcase_32 AC 25 ms
6,944 KB
testcase_33 WA -
testcase_34 AC 63 ms
6,940 KB
testcase_35 AC 6 ms
6,940 KB
testcase_36 AC 39 ms
6,944 KB
testcase_37 AC 64 ms
6,944 KB
testcase_38 AC 15 ms
6,944 KB
testcase_39 AC 20 ms
6,944 KB
testcase_40 AC 6 ms
6,944 KB
testcase_41 AC 66 ms
6,940 KB
testcase_42 AC 51 ms
6,940 KB
testcase_43 AC 73 ms
6,940 KB
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 AC 69 ms
6,944 KB
testcase_50 AC 68 ms
6,940 KB
testcase_51 AC 70 ms
6,940 KB
testcase_52 AC 69 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){
        dist[x] ^= dist[ parent[x] ];
        parent[x] = Find(parent[x]);
    }
    return parent[x];
}

int comp;

bool Union(int x, int y, int c){
    x = Find(x);
    y = Find(y);
    if(x != y){
        --comp;
        dist[y] = (dist[x] ^ dist[y] ^ c);
        parent[y] = x;
        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