結果

問題 No.2293 無向辺 2-SAT
ユーザー Meet BrahmbhattMeet Brahmbhatt
提出日時 2023-05-16 20:40:07
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,651 bytes
コンパイル時間 1,813 ms
コンパイル使用メモリ 177,820 KB
実行使用メモリ 27,264 KB
最終ジャッジ日時 2024-05-08 14:11:59
合計ジャッジ時間 15,505 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 9 ms
10,880 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 35 ms
11,008 KB
testcase_08 WA -
testcase_09 AC 124 ms
11,008 KB
testcase_10 AC 120 ms
11,008 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 88 ms
7,168 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
testcase_50 WA -
testcase_51 WA -
testcase_52 WA -
testcase_53 WA -
testcase_54 WA -
testcase_55 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

/**
 *  - Meet Brahmbhatt
 *  - Hard work always pays off
**/
#include"bits/stdc++.h"
using namespace std;

#ifdef MeetBrahmbhatt
#include "debug.h"
#else
#define dbg(...) 72
#endif

#define endl "\n"
#define int long long

const long long INF = 4e18;

class DSU {
public :
    vector<int> parent;
    vector<int> size;
    set<int> USED;
    int comps;
    DSU(int n) : parent(n), size(n), comps(n) {
        for (int i = 0; i < n; i++) {
            parent[i] = i;
            size[i] = 1;
        }
    }
    int find(int a) {
        if (parent[a] == a) return a;
        return parent[a] = find(parent[a]);
    }
    bool join(int x, int y) {
        USED.insert(x);
        USED.insert(y);
        int a = find(x);
        int b = find(y);
        if (a != b) {
            if (size[a] < size[b]) swap(a, b);
            parent[b] = a;
            size[a] += size[b];
            comps -= 1;
            return true;
        }
        return false;
    }
    void reset() {
        comps = (int) parent.size();
        for (int i : USED) {
            parent[i] = i;
            size[i] = 1;
        }
        USED.clear();
    }
    bool same(int x, int y) {
        return find(x) == find(y);
    }
    int Components() {
        return comps;
    }
};

void solve() {
    int n, q;
    cin >> n >> q;

    constexpr int MOD = 998244353;
    constexpr int HALF = 499122177;

    vector<int> P(n + 1, 1);
    for (int i = 1; i <= n; i++) {
        P[i] = (P[i - 1] * 2) % MOD;
    }
    int ans = P.back();

    DSU D(2 * n);
    while (q--) {
        int t;
        cin >> t;
        if (t == 1) {
            int u, v;
            cin >> u >> v;
            --u; --v;
            if (D.same(u, v + n)) {
                cout << 0 << endl;
            } else if (!D.same(u, v)) {
                D.join(u, v);
                D.join(u + n, v + n);
                ans *= HALF;
                ans %= MOD;
                cout << ans << endl;
            }
        } else if (t == 2) {
            int u, v;
            cin >> u >> v;
            --u; --v;
            if (D.same(u, v)) {
                cout << 0 << endl;
            } else if (!D.same(u, v + n)) {
                D.join(u, v + n);
                D.join(v, u + n);
                ans *= HALF;
                ans %= MOD;
                cout << ans << endl;
            }
        } else {
            D.reset();
            ans = P.back();
            cout << P[n] << endl;
        }
    }
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout << fixed << setprecision(9);
    int tt = 1;
    // cin >> tt;
    while (tt--) solve();
    return 0;
}
0