結果
問題 | No.2277 Honest or Dishonest ? |
ユーザー |
|
提出日時 | 2023-04-21 23:16:23 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 33 ms / 2,000 ms |
コード長 | 940 bytes |
コンパイル時間 | 1,829 ms |
コンパイル使用メモリ | 199,384 KB |
最終ジャッジ日時 | 2025-02-12 12:31:51 |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 50 |
ソースコード
#include <bits/stdc++.h>using namespace std;#ifdef _RUTHEN#include <debug.hpp>#else#define show(...) true#endif#define REP(i, n) for (int i = 0; i < (n); i++)template <class T> using V = vector<T>;#include <atcoder/modint>using mint = atcoder::modint998244353;#include <atcoder/dsu>int main() {ios::sync_with_stdio(false);cin.tie(0);int N, Q;cin >> N >> Q;atcoder::dsu uf(N + N);vector<int> A(Q), B(Q), C(Q);REP(i, Q) {cin >> A[i] >> B[i] >> C[i];A[i]--, B[i]--;if (C[i] == 0) {uf.merge(A[i], B[i]);uf.merge(A[i] + N, B[i] + N);} else {uf.merge(A[i] + N, B[i]);uf.merge(A[i], B[i] + N);}}int ok = 1;REP(i, N) if (uf.same(i, i + N)) ok = 0;mint ans = 1;REP(i, N) if (uf.leader(i) == i) ans *= 2;if (ok == 0) ans = 0;cout << ans.val() << '\n';return 0;}