結果

問題 No.2277 Honest or Dishonest ?
ユーザー achapiachapi
提出日時 2023-04-21 23:20:06
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,267 bytes
コンパイル時間 4,984 ms
コンパイル使用メモリ 265,108 KB
実行使用メモリ 12,692 KB
最終ジャッジ日時 2024-04-25 19:08:07
合計ジャッジ時間 8,863 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 2 ms
6,816 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 35 ms
6,944 KB
testcase_13 WA -
testcase_14 AC 43 ms
6,944 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 57 ms
6,944 KB
testcase_22 WA -
testcase_23 AC 74 ms
6,940 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 36 ms
6,940 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 33 ms
6,944 KB
testcase_31 AC 57 ms
7,680 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 AC 81 ms
9,088 KB
testcase_35 WA -
testcase_36 AC 52 ms
7,040 KB
testcase_37 AC 85 ms
6,940 KB
testcase_38 AC 18 ms
6,940 KB
testcase_39 AC 25 ms
6,940 KB
testcase_40 WA -
testcase_41 AC 87 ms
9,344 KB
testcase_42 AC 59 ms
8,064 KB
testcase_43 AC 90 ms
12,488 KB
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 AC 98 ms
12,544 KB
testcase_50 AC 94 ms
12,416 KB
testcase_51 AC 94 ms
12,444 KB
testcase_52 AC 91 ms
12,672 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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<bool> f2(n, true);
	for (auto s : uf.groups()){
		int ok = 2;
		for (int i : s){
			if (f[i] != -1){
				continue;
			}
			queue<int> q;
			q.push(i);
			f[i] = 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);
					}else{
						if (f[p.first] != (f[v] ^ p.second)){
							ok = 0;
						}
					}
				}
			}
			if (ok == 0){
				ok = 2;
				f[i] = 1;
				q.push(i);
				while (!q.empty()){
					int v = q.front();
					q.pop();
					for (auto p : g[v]){
						if (f2[p.first]){
							f[p.first] = (f[v] ^ p.second);
							q.push(p.first);
						}else{
							if (f[p.first] != (f[v] ^ p.second)){
								ok = 0;
							}
						}
						f2[p.first] = false;
					}
				}
			}
			if (ok == 0){
				break;
			}
		}
		ans *= ok;
	}
	cout << ans.val() << endl;
}
0