結果
問題 | No.2277 Honest or Dishonest ? |
ユーザー | tsugutsugu |
提出日時 | 2023-04-21 21:49:02 |
言語 | C++23 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 58 ms / 2,000 ms |
コード長 | 3,371 bytes |
コンパイル時間 | 3,170 ms |
コンパイル使用メモリ | 252,348 KB |
実行使用メモリ | 23,040 KB |
最終ジャッジ日時 | 2024-11-08 06:28:36 |
合計ジャッジ時間 | 7,150 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 10 ms
15,360 KB |
testcase_01 | AC | 10 ms
15,360 KB |
testcase_02 | AC | 10 ms
15,232 KB |
testcase_03 | AC | 41 ms
15,616 KB |
testcase_04 | AC | 49 ms
17,152 KB |
testcase_05 | AC | 49 ms
20,864 KB |
testcase_06 | AC | 33 ms
15,232 KB |
testcase_07 | AC | 31 ms
15,488 KB |
testcase_08 | AC | 55 ms
22,656 KB |
testcase_09 | AC | 43 ms
17,664 KB |
testcase_10 | AC | 24 ms
15,232 KB |
testcase_11 | AC | 17 ms
15,232 KB |
testcase_12 | AC | 23 ms
15,232 KB |
testcase_13 | AC | 37 ms
15,360 KB |
testcase_14 | AC | 25 ms
15,232 KB |
testcase_15 | AC | 44 ms
19,712 KB |
testcase_16 | AC | 31 ms
15,488 KB |
testcase_17 | AC | 19 ms
15,232 KB |
testcase_18 | AC | 52 ms
17,536 KB |
testcase_19 | AC | 47 ms
17,152 KB |
testcase_20 | AC | 36 ms
16,256 KB |
testcase_21 | AC | 28 ms
15,232 KB |
testcase_22 | AC | 35 ms
16,000 KB |
testcase_23 | AC | 34 ms
15,232 KB |
testcase_24 | AC | 33 ms
16,512 KB |
testcase_25 | AC | 53 ms
18,944 KB |
testcase_26 | AC | 49 ms
23,040 KB |
testcase_27 | AC | 22 ms
15,232 KB |
testcase_28 | AC | 43 ms
19,072 KB |
testcase_29 | AC | 53 ms
19,328 KB |
testcase_30 | AC | 22 ms
15,360 KB |
testcase_31 | AC | 27 ms
15,232 KB |
testcase_32 | AC | 49 ms
19,200 KB |
testcase_33 | AC | 45 ms
16,768 KB |
testcase_34 | AC | 35 ms
15,488 KB |
testcase_35 | AC | 32 ms
19,712 KB |
testcase_36 | AC | 26 ms
15,272 KB |
testcase_37 | AC | 34 ms
15,268 KB |
testcase_38 | AC | 16 ms
15,232 KB |
testcase_39 | AC | 17 ms
15,232 KB |
testcase_40 | AC | 26 ms
18,256 KB |
testcase_41 | AC | 37 ms
15,488 KB |
testcase_42 | AC | 29 ms
15,360 KB |
testcase_43 | AC | 38 ms
15,744 KB |
testcase_44 | AC | 57 ms
17,408 KB |
testcase_45 | AC | 56 ms
17,152 KB |
testcase_46 | AC | 58 ms
17,280 KB |
testcase_47 | AC | 56 ms
17,280 KB |
testcase_48 | AC | 55 ms
17,280 KB |
testcase_49 | AC | 38 ms
15,744 KB |
testcase_50 | AC | 39 ms
15,616 KB |
testcase_51 | AC | 38 ms
15,744 KB |
testcase_52 | AC | 38 ms
15,744 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; struct UnionFind { vector<int> par; UnionFind(int n) : par(n, -1) { } void init(int n) { par.assign(n, -1); } int root(int x) { if (par[x] < 0) return x; else return par[x] = root(par[x]); } bool issame(int x, int y) { return root(x) == root(y); } bool merge(int x, int y) { x = root(x); y = root(y); if (x == y) return false; if (par[x] > par[y]) swap(x, y); // merge technique par[x] += par[y]; par[y] = x; return true; } int size(int x) { return -par[root(x)]; } }; const int mod = 998244353; // const int mod = 1000000007; struct modint { long long a = 0; modint(long long x = 0) {while (x < 0) x += mod; a = x % mod;} modint(const modint &r) {a = r.a;} modint operator -(){return modint(-a);} modint operator +(const modint &r) {return modint(*this) += r;} modint operator -(const modint &r) {return modint(*this) -= r;} modint operator *(const modint &r) {return modint(*this) *= r;} modint &operator +=(const modint &r) { a += r.a; if(a >= mod) a -= mod; return *this; } modint &operator -=(const modint &r) { a -= r.a; if(a < 0) a += mod; return *this; } modint &operator *=(const modint &r) { a = a * r.a % mod; return *this; } modint pow(long long r) const { if (!r) return 1; modint x = pow(r >> 1); x *= x; if (r & 1) x *= *this; return x; } modint inverse() const { return pow(mod - 2); } modint& operator/=(const modint r) { return (*this) *= r.inverse(); } modint operator/(const modint r) const { modint res(*this); return res /= r; } }; istream &operator>>(istream &is, modint &x) { long long t; is >> t; x = t; return is; } ostream &operator<<(ostream &os, const modint& x) { return os << x.a; } const int MAX = 500044; modint fac[MAX], inv[MAX], finv[MAX]; void cominit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for(int i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * modint(i); inv[i] = - inv[mod % i] * modint(mod / i); finv[i] = finv[i - 1] * inv[i]; } } modint Com(long long n, long long k) { if(n < k) return 0; if(n < 0 || k < 0) return 0; return fac[n] * finv[k] * finv[n - k]; } modint Per(long long n, long long k) { if(n < k) return 0; if(n < 0 || k < 0) return 0; return fac[n] * finv[n - k]; } using Mint = modint; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n, q; cin >> n >> q; UnionFind uf(2 * n); for (int i = 0; i < q; i++) { 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); } } for (int i = 0; i < n; i++) { if (uf.issame(i, i + n)) { cout << 0 << '\n'; return 0; } } set<int> st; for (int i = 0; i < 2 * n; i++) { st.insert(uf.root(i)); } int cnt = st.size() / 2; cout << Mint(2).pow(cnt) << '\n'; }