Submission #73713117


Source Code Expand

#include<iostream>
#include<algorithm>
using namespace std;
#define int long long
const int N = 2e5 + 10, M = 2e5 + 10, mod = 998244353;

int n, m;
int cnt[26];
int u[N], v[N];
int fa[N];

int find(int p){
    return p == fa[p] ? p : fa[p] = find(fa[p]);
}

void merge(int x, int y){
    fa[find(x)] = find(y);
}

int __pow[N];

void init(){
    __pow[0] = 1;
    for(int i=1;i<N;i++){
        __pow[i] = (__pow[i-1] << 1) % 998244353;
    }
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    init();
    cin >> n >> m;
    int tot = 0;
    for(int i=1;i<=m;i++){
        cin >> u[i] >> v[i];
        tot = (tot + __pow[i]) % mod;
    }
    int cnt = n, ans = 0;
    for(int i=1;i<=n;i++) fa[i] = i;
    for(int i=m;i>=1;i--){
        if(find(u[i]) != find(v[i])){
            if(cnt == 2) continue;
            merge(u[i], v[i]);
            cnt --;
            ans = (ans + __pow[i]) % 998244353;
        }else{
            ans = (ans + __pow[i]) % 998244353;
        }
    }
    cout << (tot - ans + mod) % mod;
    return 0;
}

Submission Info

Submission Time
Task E - Divide Graph
User Queryme
Language C++23 (GCC 15.2.0)
Score 475
Code Size 1115 Byte
Status AC
Exec Time 21 ms
Memory 9900 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 475 / 475
Status
AC × 3
AC × 36
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 02_perfect_00.txt, 02_perfect_01.txt, 02_perfect_02.txt, 02_perfect_03.txt, 02_perfect_04.txt, 02_perfect_05.txt, 02_perfect_06.txt, 02_perfect_07.txt, 02_perfect_08.txt, 03_tree_00.txt, 03_tree_01.txt, 03_tree_02.txt, 03_tree_03.txt, 03_tree_04.txt, 03_tree_05.txt, 03_tree_06.txt, 04_handmade_00.txt, 04_handmade_01.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 2 ms 5216 KiB
00_sample_01.txt AC 2 ms 5276 KiB
00_sample_02.txt AC 2 ms 5224 KiB
01_random_00.txt AC 12 ms 7856 KiB
01_random_01.txt AC 11 ms 7580 KiB
01_random_02.txt AC 10 ms 7256 KiB
01_random_03.txt AC 3 ms 5356 KiB
01_random_04.txt AC 12 ms 7892 KiB
01_random_05.txt AC 10 ms 7232 KiB
01_random_06.txt AC 9 ms 6948 KiB
01_random_07.txt AC 9 ms 6720 KiB
01_random_08.txt AC 13 ms 7716 KiB
01_random_09.txt AC 10 ms 6896 KiB
01_random_10.txt AC 19 ms 9516 KiB
01_random_11.txt AC 19 ms 9396 KiB
01_random_12.txt AC 21 ms 9744 KiB
01_random_13.txt AC 13 ms 8044 KiB
01_random_14.txt AC 18 ms 9260 KiB
02_perfect_00.txt AC 12 ms 8300 KiB
02_perfect_01.txt AC 13 ms 8364 KiB
02_perfect_02.txt AC 13 ms 8356 KiB
02_perfect_03.txt AC 13 ms 8404 KiB
02_perfect_04.txt AC 12 ms 8300 KiB
02_perfect_05.txt AC 12 ms 8240 KiB
02_perfect_06.txt AC 13 ms 8364 KiB
02_perfect_07.txt AC 13 ms 8212 KiB
02_perfect_08.txt AC 13 ms 8364 KiB
03_tree_00.txt AC 18 ms 9892 KiB
03_tree_01.txt AC 19 ms 9900 KiB
03_tree_02.txt AC 17 ms 9836 KiB
03_tree_03.txt AC 19 ms 9872 KiB
03_tree_04.txt AC 19 ms 9772 KiB
03_tree_05.txt AC 19 ms 9780 KiB
03_tree_06.txt AC 19 ms 9780 KiB
04_handmade_00.txt AC 2 ms 5140 KiB
04_handmade_01.txt AC 15 ms 9880 KiB