結果

問題 No.2293 無向辺 2-SAT
ユーザー kwm_tkwm_t
提出日時 2023-05-05 23:28:29
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 389 ms / 4,000 ms
コード長 2,346 bytes
コンパイル時間 4,111 ms
コンパイル使用メモリ 270,164 KB
実行使用メモリ 15,104 KB
最終ジャッジ日時 2024-05-02 18:47:36
合計ジャッジ時間 20,056 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 3 ms
5,248 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 389 ms
15,104 KB
testcase_04 AC 204 ms
5,760 KB
testcase_05 AC 191 ms
5,760 KB
testcase_06 AC 165 ms
5,760 KB
testcase_07 AC 53 ms
5,760 KB
testcase_08 AC 149 ms
5,760 KB
testcase_09 AC 110 ms
5,632 KB
testcase_10 AC 115 ms
5,760 KB
testcase_11 AC 216 ms
5,760 KB
testcase_12 AC 160 ms
5,760 KB
testcase_13 AC 141 ms
5,632 KB
testcase_14 AC 135 ms
5,632 KB
testcase_15 AC 134 ms
5,632 KB
testcase_16 AC 197 ms
5,760 KB
testcase_17 AC 255 ms
6,784 KB
testcase_18 AC 172 ms
5,632 KB
testcase_19 AC 90 ms
5,376 KB
testcase_20 AC 187 ms
5,632 KB
testcase_21 AC 153 ms
5,632 KB
testcase_22 AC 222 ms
6,016 KB
testcase_23 AC 227 ms
6,016 KB
testcase_24 AC 225 ms
6,016 KB
testcase_25 AC 218 ms
6,016 KB
testcase_26 AC 225 ms
6,016 KB
testcase_27 AC 227 ms
6,016 KB
testcase_28 AC 234 ms
6,016 KB
testcase_29 AC 230 ms
6,016 KB
testcase_30 AC 232 ms
6,016 KB
testcase_31 AC 225 ms
6,016 KB
testcase_32 AC 115 ms
5,632 KB
testcase_33 AC 115 ms
5,632 KB
testcase_34 AC 117 ms
5,632 KB
testcase_35 AC 117 ms
5,760 KB
testcase_36 AC 118 ms
5,760 KB
testcase_37 AC 110 ms
5,632 KB
testcase_38 AC 114 ms
5,632 KB
testcase_39 AC 114 ms
5,632 KB
testcase_40 AC 115 ms
5,632 KB
testcase_41 AC 84 ms
5,632 KB
testcase_42 AC 94 ms
5,632 KB
testcase_43 AC 114 ms
5,632 KB
testcase_44 AC 126 ms
5,632 KB
testcase_45 AC 138 ms
5,760 KB
testcase_46 AC 147 ms
5,632 KB
testcase_47 AC 159 ms
5,632 KB
testcase_48 AC 169 ms
5,632 KB
testcase_49 AC 177 ms
5,632 KB
testcase_50 AC 185 ms
5,632 KB
testcase_51 AC 195 ms
5,632 KB
testcase_52 AC 205 ms
5,760 KB
testcase_53 AC 221 ms
5,888 KB
testcase_54 AC 248 ms
6,144 KB
testcase_55 AC 265 ms
6,784 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; }

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int n, q; cin >> n >> q;
	vector<int>t(q), u(q), v(q);
	rep(i, q) {
		cin >> t[i];
		if (t[i] <= 2) {
			cin >> u[i] >> v[i];
			u[i]--, v[i]--;
		}
	}
	int l = 0;
	for (; l < q;) {
		int r = l + 1;
		while ((r < q) && (3 != t[r])) {
			r++;
		}
		//cout << l << " " << r << endl;
		map<int, int>mp;
		for (int i = l; i < r; ++i) {
			if (3 == t[i])continue;
			if (!mp.count(u[i])) mp[u[i]] = mp.size();
			if (!mp.count(v[i])) mp[v[i]] = mp.size();
		}
		int sz = mp.size();
		//cout << sz << endl;
		dsu uf(sz * 2);
		int g = sz * 2;
		bool chk = true;
		for (int i = l; i < r; ++i) {
			if (1 == t[i]) {
				int x0 = mp[u[i]] * 2;
				int x1 = x0 + 1;
				int y0 = mp[v[i]] * 2;
				int y1 = y0 + 1;
				if (uf.same(x0, y1) || uf.same(x1, y0)) {
					chk = false;
				}
				else {
					if (!uf.same(x0, y0)) {
						uf.merge(x0, y0);
						g--;
					}
					if (!uf.same(x1, y1)) {
						uf.merge(x1, y1);
						g--;
					}
				}
			}
			else if (2 == t[i]) {
				int x0 = mp[u[i]] * 2;
				int x1 = x0 + 1;
				int y0 = mp[v[i]] * 2;
				int y1 = y0 + 1;
				if (uf.same(x0, y0) || uf.same(x1, y1)) {
					chk = false;
				}
				else {
					if (!uf.same(x0, y1)) {
						uf.merge(x0, y1);
						g--;
					}
					if (!uf.same(x1, y0)) {
						uf.merge(x1, y0);
						g--;
					}
				}
			}
			if (!chk) {
				cout << 0 << endl;
				continue;
			}
			mint ans = pow_mod(2, n - sz + g / 2, mod);
			cout << ans.val() << endl;
		}
		l = r;
	}
	return 0;
}
0