結果

問題 No.2277 Honest or Dishonest ?
ユーザー srjywrdnprkt
提出日時 2023-04-22 02:23:13
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 147 ms / 2,000 ms
コード長 1,571 bytes
コンパイル時間 1,243 ms
コンパイル使用メモリ 114,528 KB
最終ジャッジ日時 2025-02-12 12:50:12
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 50
権限があれば一括ダウンロードができます

ソースコード

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