結果

問題 No.2277 Honest or Dishonest ?
ユーザー srjywrdnprktsrjywrdnprkt
提出日時 2023-04-22 02:23:13
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 106 ms / 2,000 ms
コード長 1,571 bytes
コンパイル時間 1,388 ms
コンパイル使用メモリ 117,756 KB
実行使用メモリ 9,684 KB
最終ジャッジ日時 2024-04-25 19:11:58
合計ジャッジ時間 5,766 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 80 ms
7,680 KB
testcase_04 AC 75 ms
8,704 KB
testcase_05 AC 24 ms
6,940 KB
testcase_06 AC 69 ms
6,944 KB
testcase_07 AC 56 ms
6,944 KB
testcase_08 AC 19 ms
6,940 KB
testcase_09 AC 48 ms
7,168 KB
testcase_10 AC 43 ms
6,940 KB
testcase_11 AC 20 ms
6,940 KB
testcase_12 AC 35 ms
6,940 KB
testcase_13 AC 75 ms
7,168 KB
testcase_14 AC 42 ms
6,944 KB
testcase_15 AC 23 ms
6,944 KB
testcase_16 AC 54 ms
6,940 KB
testcase_17 AC 25 ms
6,944 KB
testcase_18 AC 70 ms
8,448 KB
testcase_19 AC 71 ms
8,448 KB
testcase_20 AC 56 ms
7,296 KB
testcase_21 AC 54 ms
6,944 KB
testcase_22 AC 50 ms
6,944 KB
testcase_23 AC 74 ms
6,944 KB
testcase_24 AC 44 ms
6,940 KB
testcase_25 AC 54 ms
7,808 KB
testcase_26 AC 11 ms
6,944 KB
testcase_27 AC 36 ms
6,944 KB
testcase_28 AC 24 ms
6,940 KB
testcase_29 AC 37 ms
6,940 KB
testcase_30 AC 32 ms
6,940 KB
testcase_31 AC 55 ms
6,944 KB
testcase_32 AC 33 ms
6,940 KB
testcase_33 AC 73 ms
8,192 KB
testcase_34 AC 77 ms
8,192 KB
testcase_35 AC 8 ms
6,944 KB
testcase_36 AC 49 ms
6,940 KB
testcase_37 AC 77 ms
7,040 KB
testcase_38 AC 17 ms
6,944 KB
testcase_39 AC 25 ms
6,940 KB
testcase_40 AC 9 ms
6,940 KB
testcase_41 AC 91 ms
8,320 KB
testcase_42 AC 61 ms
6,948 KB
testcase_43 AC 96 ms
9,600 KB
testcase_44 AC 106 ms
9,600 KB
testcase_45 AC 95 ms
9,600 KB
testcase_46 AC 96 ms
9,472 KB
testcase_47 AC 91 ms
9,472 KB
testcase_48 AC 96 ms
9,644 KB
testcase_49 AC 102 ms
9,600 KB
testcase_50 AC 99 ms
9,600 KB
testcase_51 AC 100 ms
9,684 KB
testcase_52 AC 99 ms
9,600 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cmath>
#include <map>
#include <set>
#include <iomanip>
#include <queue>
#include <algorithm>
#include <numeric>
#include <deque>
#include <complex>
#include <cassert>

using namespace std;


long long mod_exp(long long b, long long e, long long m){
    if (e > 0 && b == 0) return 0;
    long long ans = 1;
    b %= m;

    while (e > 0){
        if ((e & 1LL)) ans = (ans * b) % m;
        e = e >> 1LL;
        b = (b*b) % m;
    }

    return ans;
}
const long long modc = 998244353;

int main(){

    int N, M, A, B, C, start, from, to, x;
    long long ans=1;
    cin >> N >> M;
    queue<int> que;
    vector<vector<pair<int, int>>> E(N);
    vector<int> dist(N, -1);

    for (int i=0; i < M; i++){
        cin >> A >> B >> C;
        A--; B--;
        E[A].push_back({B, C});
        E[B].push_back({A, C});
    }

    for (int i=0; i<N; i++){
        if (dist[i] != -1) continue;
        ans *= 2;
        ans %= modc;
        start = i;
        dist[start] = 0;
        que.push(start);

        while(!que.empty()){
            from = que.front();
            que.pop();
            for (auto [to, C] : E[from]){
                x = dist[from] ^ C;
                if (dist[to] != -1){
                    if (dist[to] == x) continue;
                    else{
                        cout << 0 << endl;
                        return 0;
                    }
                }
                dist[to] = x;
                que.push(to);
            }
        }
    }

    cout << ans << endl;

    return 0;
}
0