結果

問題 No.2277 Honest or Dishonest ?
ユーザー kwm_tkwm_t
提出日時 2023-04-21 23:00:28
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 57 ms / 2,000 ms
コード長 1,614 bytes
コンパイル時間 4,185 ms
コンパイル使用メモリ 256,068 KB
実行使用メモリ 13,940 KB
最終ジャッジ日時 2024-04-25 19:05:18
合計ジャッジ時間 7,590 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
8,172 KB
testcase_01 AC 3 ms
8,264 KB
testcase_02 AC 3 ms
8,172 KB
testcase_03 AC 44 ms
13,136 KB
testcase_04 AC 44 ms
12,800 KB
testcase_05 AC 14 ms
9,804 KB
testcase_06 AC 37 ms
12,356 KB
testcase_07 AC 30 ms
11,540 KB
testcase_08 AC 13 ms
9,524 KB
testcase_09 AC 28 ms
10,892 KB
testcase_10 AC 24 ms
10,740 KB
testcase_11 AC 13 ms
9,352 KB
testcase_12 AC 20 ms
9,864 KB
testcase_13 AC 43 ms
12,692 KB
testcase_14 AC 22 ms
10,024 KB
testcase_15 AC 13 ms
9,536 KB
testcase_16 AC 32 ms
11,524 KB
testcase_17 AC 18 ms
10,076 KB
testcase_18 AC 40 ms
12,376 KB
testcase_19 AC 43 ms
12,612 KB
testcase_20 AC 34 ms
11,968 KB
testcase_21 AC 33 ms
11,328 KB
testcase_22 AC 29 ms
11,292 KB
testcase_23 AC 41 ms
11,856 KB
testcase_24 AC 27 ms
10,832 KB
testcase_25 AC 31 ms
11,052 KB
testcase_26 AC 9 ms
9,088 KB
testcase_27 AC 22 ms
10,688 KB
testcase_28 AC 15 ms
9,560 KB
testcase_29 AC 22 ms
10,076 KB
testcase_30 AC 21 ms
10,484 KB
testcase_31 AC 33 ms
12,140 KB
testcase_32 AC 20 ms
10,188 KB
testcase_33 AC 43 ms
12,688 KB
testcase_34 AC 47 ms
13,448 KB
testcase_35 AC 7 ms
8,652 KB
testcase_36 AC 31 ms
11,344 KB
testcase_37 AC 46 ms
12,672 KB
testcase_38 AC 12 ms
9,280 KB
testcase_39 AC 16 ms
9,760 KB
testcase_40 AC 7 ms
8,620 KB
testcase_41 AC 51 ms
13,564 KB
testcase_42 AC 36 ms
12,084 KB
testcase_43 AC 52 ms
13,868 KB
testcase_44 AC 57 ms
13,820 KB
testcase_45 AC 51 ms
13,736 KB
testcase_46 AC 51 ms
13,940 KB
testcase_47 AC 50 ms
13,876 KB
testcase_48 AC 53 ms
13,884 KB
testcase_49 AC 54 ms
13,636 KB
testcase_50 AC 52 ms
13,800 KB
testcase_51 AC 50 ms
13,888 KB
testcase_52 AC 51 ms
13,928 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
//using mint = modint1000000007;
//const int mod = 1000000007;
using mint = modint998244353;
const int mod = 998244353;
//const int INF = 1e9;
//const long long LINF = 1e18;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i,l,r)for(int i=(l);i<(r);++i)
#define rrep(i, n) for (int i = (n-1); i >= 0; --i)
#define rrep2(i,l,r)for(int i=(r-1);i>=(l);--i)
#define all(x) (x).begin(),(x).end()
#define allR(x) (x).rbegin(),(x).rend()
#define endl "\n"
#define P pair<int,int>
template<typename A, typename B> inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; }
template<typename A, typename B> inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; }
struct Edge {
	int to, type;
	Edge(int _to, int _type) :to(_to), type(_type) {}
};
vector<Edge>g[200005];
int col[100005];
bool dfs(int v, int p = -1) {
	if (-1 == p)col[v] = 0;
	bool ret = true;
	for (Edge e : g[v]) {
		int nx = col[v];
		if (e.type)nx ^= 1;
		if (-1 != col[e.to]) {
			if (nx != col[e.to])ret = false;
		}
		else {
			col[e.to] = nx;
			ret &= dfs(e.to, v);
		}
	}
	return ret;
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int n, q; cin >> n >> q;
	while (q--) {
		int a, b, c; cin >> a >> b >> c;
		a--, b--;
		g[a].push_back({ b,c });
		g[b].push_back({ a,c });
	}
	rep(i, n)col[i] = -1;
	mint ans = 1;
	rep(i, n) {
		if (-1 != col[i])continue;
		auto get = dfs(i);
		if (get)ans *= 2;
		else ans *= 0;
	}
	cout << ans.val() << endl;
	return 0;
}
0