結果
問題 | No.2277 Honest or Dishonest ? |
ユーザー |
|
提出日時 | 2023-04-21 21:33:32 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 61 ms / 2,000 ms |
コード長 | 891 bytes |
コンパイル時間 | 3,284 ms |
コンパイル使用メモリ | 252,008 KB |
実行使用メモリ | 11,136 KB |
最終ジャッジ日時 | 2024-11-08 06:24:21 |
合計ジャッジ時間 | 6,655 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 50 |
ソースコード
#include <bits/stdc++.h>using namespace std;using LL = long long;constexpr LL mod = 998244353;int main() {ios::sync_with_stdio(false);cin.tie(nullptr);int n, m;cin >> n >> m;vector<vector<pair<int, int>>> g(n + 1);for (int i = 0, a, b, c; i < m; i += 1) {cin >> a >> b >> c;g[a].emplace_back(b, c);g[b].emplace_back(a, c);}vector<int> vis(n + 1, -1);LL ans = 1;function<void(int)> dfs = [&](int u) {for (auto [v, w] : g[u]) {if (vis[v] == -1) {vis[v] = vis[u] ^ w;dfs(v);} else if (vis[v] != (vis[u] ^ w)) {ans = 0;}}};for (int i = 1; i <= n; i += 1) {if (vis[i] == -1) {vis[i] = 0;dfs(i);ans = ans * 2 % mod;}}cout << ans;}