結果
| 問題 |
No.2277 Honest or Dishonest ?
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-04-21 22:07:08 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,540 bytes |
| コンパイル時間 | 4,475 ms |
| コンパイル使用メモリ | 262,172 KB |
| 最終ジャッジ日時 | 2025-02-12 11:43:49 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 34 WA * 16 |
ソースコード
#include <bits/stdc++.h>
#include <atcoder/all>
using mint = atcoder::modint998244353;
using namespace std;
int main() {
int n, m;
cin >> n >> m;
atcoder::dsu uf(n);
vector<vector<pair<int, int>>> g(n);
for (int i = 0; i < m; i++){
int a, b, c;
cin >> a >> b >> c;
a--;
b--;
g[a].push_back({b, c});
uf.merge(a, b);
}
mint ans = 1;
vector<int> f(n, -1);
vector<int> f2(n, -1);
vector<bool> f_(n);
vector<bool> f2_(n);
for (auto s : uf.groups()){
int c = 0;
queue<int> q;
q.push(s[0]);
f[s[0]] = 0;
while (!q.empty()){
int v = q.front();
q.pop();
for (auto p : g[v]){
if (f[p.first] == -1){
f[p.first] = f[v] ^ p.second;
q.push(p.first);
}
}
}
bool ok = true;
q.push(s[0]);
while (!q.empty()){
int v = q.front();
q.pop();
for (auto p : g[v]){
if (f_[p.first]){
continue;
}
if (f[p.first] != (f[v] ^ p.second)){
ok = false;
}
f_[p.first] = true;
q.push(p.first);
}
}
c += ok;
q.push(s[0]);
f2[s[0]] = 1;
while (!q.empty()){
int v = q.front();
q.pop();
for (auto p : g[v]){
if (f2[p.first] == -1){
f2[p.first] = f2[v] ^ p.second;
q.push(p.first);
}
}
}
ok = true;
q.push(s[0]);
while (!q.empty()){
int v = q.front();
q.pop();
for (auto p : g[v]){
if (f2_[p.first]){
continue;
}
if (f2[p.first] != (f2[v] ^ p.second)){
ok = false;
}
f2_[p.first] = true;
q.push(p.first);
}
}
c += ok;
ans *= c;
}
cout << ans.val() << endl;
}