結果

問題 No.2277 Honest or Dishonest ?
ユーザー KKT89KKT89
提出日時 2023-04-21 22:29:16
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 54 ms / 2,000 ms
コード長 1,317 bytes
コンパイル時間 2,767 ms
コンパイル使用メモリ 215,152 KB
実行使用メモリ 10,880 KB
最終ジャッジ日時 2024-04-25 19:02:12
合計ジャッジ時間 6,290 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 42 ms
8,960 KB
testcase_04 AC 42 ms
9,600 KB
testcase_05 AC 15 ms
6,940 KB
testcase_06 AC 35 ms
7,552 KB
testcase_07 AC 30 ms
7,168 KB
testcase_08 AC 12 ms
6,944 KB
testcase_09 AC 28 ms
7,680 KB
testcase_10 AC 23 ms
6,940 KB
testcase_11 AC 11 ms
6,940 KB
testcase_12 AC 16 ms
6,944 KB
testcase_13 AC 41 ms
8,448 KB
testcase_14 AC 18 ms
6,940 KB
testcase_15 AC 11 ms
6,944 KB
testcase_16 AC 28 ms
7,296 KB
testcase_17 AC 14 ms
6,944 KB
testcase_18 AC 39 ms
9,344 KB
testcase_19 AC 38 ms
9,344 KB
testcase_20 AC 30 ms
8,064 KB
testcase_21 AC 27 ms
6,940 KB
testcase_22 AC 25 ms
7,424 KB
testcase_23 AC 37 ms
7,168 KB
testcase_24 AC 23 ms
6,944 KB
testcase_25 AC 28 ms
8,064 KB
testcase_26 AC 7 ms
6,944 KB
testcase_27 AC 18 ms
6,940 KB
testcase_28 AC 13 ms
6,940 KB
testcase_29 AC 20 ms
7,040 KB
testcase_30 AC 18 ms
6,944 KB
testcase_31 AC 31 ms
7,680 KB
testcase_32 AC 18 ms
6,940 KB
testcase_33 AC 38 ms
9,216 KB
testcase_34 AC 44 ms
9,344 KB
testcase_35 AC 6 ms
6,944 KB
testcase_36 AC 28 ms
7,168 KB
testcase_37 AC 39 ms
7,936 KB
testcase_38 AC 9 ms
6,940 KB
testcase_39 AC 13 ms
6,940 KB
testcase_40 AC 5 ms
6,940 KB
testcase_41 AC 44 ms
9,856 KB
testcase_42 AC 32 ms
7,936 KB
testcase_43 AC 50 ms
10,624 KB
testcase_44 AC 47 ms
10,752 KB
testcase_45 AC 48 ms
10,752 KB
testcase_46 AC 45 ms
10,752 KB
testcase_47 AC 49 ms
10,880 KB
testcase_48 AC 48 ms
10,752 KB
testcase_49 AC 50 ms
10,752 KB
testcase_50 AC 50 ms
10,752 KB
testcase_51 AC 51 ms
10,752 KB
testcase_52 AC 54 ms
10,752 KB
権限があれば一括ダウンロードができます

ソースコード

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