結果
問題 |
No.2277 Honest or Dishonest ?
|
ユーザー |
|
提出日時 | 2023-04-21 22:32:49 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,097 bytes |
コンパイル時間 | 1,958 ms |
コンパイル使用メモリ | 194,352 KB |
最終ジャッジ日時 | 2025-02-12 12:08:55 |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 24 WA * 26 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; const int maxn = 100005; const int mod = 998244353; int a[maxn],b[maxn],c[maxn]; int parent[maxn],dist[maxn]; int Find(int x){ if(parent[x] != x){ dist[x] ^= dist[ parent[x] ]; parent[x] = Find(parent[x]); } return parent[x]; } int comp; bool Union(int x, int y, int c){ int rx = Find(x); int ry = Find(y); if(rx != ry){ --comp; dist[ry] = (dist[x] ^ dist[y] ^ c); parent[ry] = rx; return true; } bool ok = (dist[y] ^ dist[x]) == c; return ok; } int main(){ int N,Q; cin >> N >> Q; for(int i = 0;i < Q;++i){ cin >> a[i] >> b[i] >> c[i]; } for(int i = 1;i <= N;++i){ parent[i] = i; dist[i] = 0; } comp = N; ll ans = 1; for(int i = 0;i < Q;++i){ if(!Union(a[i], b[i], c[i])){ ans = 0; break; } } if(ans){ for(int i = 1;i <= comp;++i){ ans = ans * 2 % mod; } } cout << ans << endl; return 0; }