Submission #73705178


Source Code Expand

#include<bits/stdc++.h>
#include<atcoder/all>
using namespace std;
using ll = long long;
#define rep(i, n) for(int  i = 0; i < (n); ++i)
template<typename T> bool chmin(T& a, T b){if(a > b){a = b; return true;} return false;}
template<typename T> bool chmax(T& a, T b){if(a < b){a = b; return true;} return false;}
const long long INF = 1LL << 60;
using Graph = vector<vector<int>>;
int gcd(int a, int b){
    if(b == 0) return a;  
    else return gcd(b, a%b);
}
struct Compare {
    bool operator()(const pair<ll, int>& a, const pair<ll, int>& b) {
        return a.first > b.first;  
    }
};
using namespace atcoder;
using mint = modint998244353;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n,m; cin >> n >> m;
    dsu d(n);
    vector<pair<int,int>> edge;
    rep(i,m){
        int u,v; cin >> u >> v;
        u--; v--;
        edge.push_back({u,v});
    }
    int co = n;
    map<int, mint> mp;
    mint now = 2;
    for(int i=1;i<=m;i++){
        mp[i] = now;
        now *= 2;
    }
    mint ans = 0;
    for(int i=m;i>0;i--){
        auto [u,v] = edge[i-1];
        if(d.same(u,v)) continue;
        if(co == 2){
            ans += mp[i];
        }else{
            d.merge(u, v);
            co--;
        }
    }
    cout << ans.val() << endl;
}

Submission Info

Submission Time
Task E - Divide Graph
User motomoto0001
Language C++23 (GCC 15.2.0)
Score 475
Code Size 1339 Byte
Status AC
Exec Time 46 ms
Memory 15148 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 1 ms 3604 KiB
00_sample_01.txt AC 1 ms 3608 KiB
00_sample_02.txt AC 1 ms 3536 KiB
01_random_00.txt AC 34 ms 13008 KiB
01_random_01.txt AC 29 ms 11540 KiB
01_random_02.txt AC 24 ms 10324 KiB
01_random_03.txt AC 2 ms 4208 KiB
01_random_04.txt AC 33 ms 12468 KiB
01_random_05.txt AC 23 ms 9992 KiB
01_random_06.txt AC 19 ms 8588 KiB
01_random_07.txt AC 18 ms 8616 KiB
01_random_08.txt AC 30 ms 11180 KiB
01_random_09.txt AC 20 ms 8976 KiB
01_random_10.txt AC 44 ms 14652 KiB
01_random_11.txt AC 43 ms 14360 KiB
01_random_12.txt AC 45 ms 14732 KiB
01_random_13.txt AC 28 ms 10952 KiB
01_random_14.txt AC 39 ms 13184 KiB
02_perfect_00.txt AC 37 ms 14264 KiB
02_perfect_01.txt AC 38 ms 14276 KiB
02_perfect_02.txt AC 38 ms 14272 KiB
02_perfect_03.txt AC 43 ms 14296 KiB
02_perfect_04.txt AC 37 ms 14268 KiB
02_perfect_05.txt AC 46 ms 14272 KiB
02_perfect_06.txt AC 38 ms 14356 KiB
02_perfect_07.txt AC 38 ms 14268 KiB
02_perfect_08.txt AC 38 ms 14272 KiB
03_tree_00.txt AC 43 ms 15128 KiB
03_tree_01.txt AC 46 ms 14996 KiB
03_tree_02.txt AC 43 ms 15148 KiB
03_tree_03.txt AC 44 ms 15044 KiB
03_tree_04.txt AC 44 ms 15064 KiB
03_tree_05.txt AC 45 ms 14940 KiB
03_tree_06.txt AC 45 ms 15148 KiB
04_handmade_00.txt AC 1 ms 3508 KiB
04_handmade_01.txt AC 42 ms 15064 KiB