結果

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

ソースコード

diff #

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
    return (ull)rng() % B;
}
inline double time() {
    return static_cast<long double>(chrono::duration_cast<chrono::nanoseconds>(chrono::steady_clock::now().time_since_epoch()).count()) * 1e-9;
}

constexpr ll mod = 998244353;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n,q; cin >> n >> q;
    vector<vector<pair<int,int>>> g(n);
    while (q--) {
        int a,b,c; cin >> a >> b >> c;
        a--; b--;
        g[a].push_back({b,c});
        g[b].push_back({a,c});
    }
    ll res = 1;
    vector<int> col(n, -1);
    for (int i = 0; i < n; ++i) {
        if (col[i] != -1) continue;
        res *= 2; res %= mod;
        col[i] = 0;
        auto dfs = [&](auto dfs,int s) -> void {
            for (auto t:g[s]) {
                if (col[t.first] == -1) {
                    col[t.first] = col[s]^t.second;
                    dfs(dfs, t.first);
                }
                else {
                    if (col[t.first] != (col[s]^t.second)) res = 0;
                }
            }
        };
        dfs(dfs,i);
    }
    cout << res << endl;
}
0