結果

問題 No.2277 Honest or Dishonest ?
ユーザー Shreyan RayShreyan Ray
提出日時 2023-04-21 21:52:10
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,854 bytes
コンパイル時間 2,405 ms
コンパイル使用メモリ 198,036 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-25 18:55:44
合計ジャッジ時間 4,565 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 9 ms
6,940 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 7 ms
6,944 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 8 ms
6,944 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 28 ms
6,944 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 4 ms
6,940 KB
testcase_27 AC 14 ms
6,940 KB
testcase_28 AC 8 ms
6,944 KB
testcase_29 AC 13 ms
6,944 KB
testcase_30 AC 12 ms
6,940 KB
testcase_31 AC 21 ms
6,940 KB
testcase_32 AC 11 ms
6,944 KB
testcase_33 WA -
testcase_34 AC 28 ms
6,940 KB
testcase_35 AC 4 ms
6,944 KB
testcase_36 AC 16 ms
6,944 KB
testcase_37 AC 30 ms
6,940 KB
testcase_38 AC 7 ms
6,940 KB
testcase_39 AC 9 ms
6,940 KB
testcase_40 AC 4 ms
6,940 KB
testcase_41 AC 30 ms
6,944 KB
testcase_42 AC 22 ms
6,944 KB
testcase_43 AC 31 ms
6,940 KB
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 AC 32 ms
6,940 KB
testcase_50 AC 33 ms
6,944 KB
testcase_51 AC 34 ms
6,940 KB
testcase_52 AC 33 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define INF (int)1e18
#define f first
#define s second

mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count());
int n, q;
const int N = 1e5 + 69;
pair <int, int> root[N];
bool good[N];
const int mod = 998244353;
bool bad = false;

pair <int, int> find(int x){
    if (root[x].f == x){
        return root[x];
    } else {
        auto p1 = find(root[x].f);
        p1.s ^= root[x].s;
        return root[x] = p1;
    }
}

void unite(int x, int y, int d){
    pair <int, int> p1 = find(x);
    pair <int, int> p2 = find(y);
    d ^= p1.s;
    d ^= p2.s;
    
    if (p1.f != p2.f){
        root[p1.f] = {p2.f, d};
        good[p2.f] &= good[p1.f];
    } else {
        if (d != 0) {
            good[p1.f] = false;
            bad = true;
        }
    }
}

void Solve() 
{
    cin >> n >> q;
    for (int i = 1; i <= n; i++){
        root[i] = {i, 1};
        good[i] = true;
    }
    
    for (int i = 1; i <= q; i++){
        int u, v, d; cin >> u >> v >> d;
        
        unite(u, v, d);
    }
    
    if (bad) {
        cout << 0 << "\n";
        return;
    }
    int ans = 1;
    for (int i = 1; i <= n; i++){
        if (i == find(i).f){
            if (good[i]) ans *= 2, ans %= mod;
            else ans = 0;
        }
    }
    
    cout << ans << "\n";
}

int32_t main() 
{
    auto begin = std::chrono::high_resolution_clock::now();
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int t = 1;
  //  cin >> t;
    for(int i = 1; i <= t; i++) 
    {
        //cout << "Case #" << i << ": ";
        Solve();
    }
    auto end = std::chrono::high_resolution_clock::now();
    auto elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin);
   // cerr << "Time measured: " << elapsed.count() * 1e-9 << " seconds.\n"; 
    return 0;
}
0