結果
問題 |
No.2277 Honest or Dishonest ?
|
ユーザー |
|
提出日時 | 2023-04-21 23:30:57 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 42 ms / 2,000 ms |
コード長 | 855 bytes |
コンパイル時間 | 2,191 ms |
コンパイル使用メモリ | 205,520 KB |
最終ジャッジ日時 | 2025-02-12 12:35:57 |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
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/dsu> #include <atcoder/modint> using mint = atcoder::modint998244353; int main() { ios::sync_with_stdio(false); cin.tie(0); int N, Q; cin >> N >> Q; atcoder::dsu uf(N + N); REP(i, Q) { int a, b, c; cin >> a >> b >> c; a--, b--; if (c == 0) { uf.merge(a, b); uf.merge(a + N, b + N); } else { uf.merge(a + N, b); uf.merge(a, b + N); } } int ok = 1; REP(i, N) if (uf.same(i, i + N)) ok = 0; mint ans = ok ? mint(2).pow(uf.groups().size() / 2) : 0; cout << ans.val() << '\n'; return 0; }