結果
問題 |
No.2277 Honest or Dishonest ?
|
ユーザー |
![]() |
提出日時 | 2023-05-19 11:24:25 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 54 ms / 2,000 ms |
コード長 | 1,180 bytes |
コンパイル時間 | 654 ms |
コンパイル使用メモリ | 60,380 KB |
実行使用メモリ | 9,472 KB |
最終ジャッジ日時 | 2024-12-17 19:20:16 |
合計ジャッジ時間 | 4,328 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 50 |
コンパイルメッセージ
main.cpp: In function 'int main()': main.cpp:60:19: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions] 60 | for (auto [v, c]: nbrs[u]) { | ^
ソースコード
/* -*- coding: utf-8 -*- * * 2277.cc: No.2277 Honest or Dishonest ? - yukicoder */ #include<cstdio> #include<vector> #include<queue> #include<algorithm> #include<utility> using namespace std; /* constant */ const int MAX_N = 100000; const int MAX_QN = 100000; const int MOD = 998244353; /* typedef */ typedef long long ll; typedef queue<int> qi; typedef pair<int,int> pii; typedef vector<pii> vpii; /* global variables */ vpii nbrs[MAX_N]; int ds[MAX_N]; /* subroutines */ /* main */ int main() { int n, qn; scanf("%d%d", &n, &qn); for (int i = 0; i < qn; i++) { int ai, bi, ci; scanf("%d%d%d", &ai, &bi, &ci); ai--, bi--; nbrs[ai].push_back({bi, ci}); nbrs[bi].push_back({ai, ci}); } int ans = 1; fill(ds, ds + n, -1); for (int st = 0; st < n; st++) if (ds[st] < 0) { ans = (ll)ans * 2 % MOD; ds[st] = 0; qi q; q.push(st); while (! q.empty()) { int u = q.front(); q.pop(); for (auto [v, c]: nbrs[u]) { if (ds[v] < 0) { ds[v] = ds[u] ^ c; q.push(v); } else if (ds[v] != (ds[u] ^ c)) { puts("0"); return 0; } } } } printf("%d\n", ans); return 0; }