提出 #73705250


ソースコード 拡げる

#include <algorithm>
#include <atcoder/all>
#include <cmath>
#include <iostream>
#include <map>
//#include <numeric>
#include <queue>
//#include <ranges>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define pb push_back
#define fr first
#define sc second
#define sor(v) sort(v.begin(), v.end())
#define rev(v) reverse(v.begin(), v.end())
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using pint = pair<int,int>;
//using pll = pair<ll,ll>;
//using pqdec = priority_queue<int,vector<int>,greater<int>>;
//using pqdecl = priority_queue<ll,vector<ll>,greater<ll>>;
template <typename T>
using graph = vector<vector<T>>;
const ll LLMAX = 9223372*1e10;
const int IMAX = 214*1e7;
/*--------考察--------------------
----------CODING----------------*/
using mint = atcoder::modint998244353;
vector<mint> w;
auto init(int m){
    mint x = 1;
    rep(i,m){
        x *= 2;
        w.pb(x);
    }
}
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n,m; cin >> n >> m;
    init(m);
    atcoder::dsu d(n);
    vector<pint> v(m);
    for(auto&[a,b]:v){cin >> a >> b; a--; b--;}
    mint ans = 0;
    int size = n;
    for(int i = m-1; i >= 0; i--){
        auto[a,b] = v[i];
        if(size <= 2 && !d.same(a,b)){
            ans += w[i];
            continue;
        }
        if(!d.same(a,b)) size--;
        d.merge(a,b);
        /*auto g = d.groups();
        cout << "loop" << i << endl;
        for(auto gg:g){
            for(auto e:gg) cout << e << " ";
            cout << endl;
        }*/
    }
    cout << ans.val() << endl;
}

提出情報

提出日時
問題 E - Divide Graph
ユーザ scotch_at
言語 C++23 (GCC 15.2.0)
得点 475
コード長 1705 Byte
結果 AC
実行時間 18 ms
メモリ 6668 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 475 / 475
結果
AC × 3
AC × 36
セット名 テストケース
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
ケース名 結果 実行時間 メモリ
00_sample_00.txt AC 1 ms 3480 KiB
00_sample_01.txt AC 1 ms 3572 KiB
00_sample_02.txt AC 1 ms 3536 KiB
01_random_00.txt AC 11 ms 5580 KiB
01_random_01.txt AC 10 ms 5196 KiB
01_random_02.txt AC 9 ms 4924 KiB
01_random_03.txt AC 2 ms 3676 KiB
01_random_04.txt AC 12 ms 5500 KiB
01_random_05.txt AC 9 ms 4744 KiB
01_random_06.txt AC 7 ms 4552 KiB
01_random_07.txt AC 8 ms 4560 KiB
01_random_08.txt AC 11 ms 5180 KiB
01_random_09.txt AC 8 ms 4684 KiB
01_random_10.txt AC 17 ms 6468 KiB
01_random_11.txt AC 16 ms 6548 KiB
01_random_12.txt AC 18 ms 6456 KiB
01_random_13.txt AC 11 ms 5436 KiB
01_random_14.txt AC 16 ms 6056 KiB
02_perfect_00.txt AC 12 ms 5812 KiB
02_perfect_01.txt AC 13 ms 5764 KiB
02_perfect_02.txt AC 12 ms 5828 KiB
02_perfect_03.txt AC 13 ms 5820 KiB
02_perfect_04.txt AC 12 ms 5844 KiB
02_perfect_05.txt AC 12 ms 5768 KiB
02_perfect_06.txt AC 12 ms 5888 KiB
02_perfect_07.txt AC 13 ms 5836 KiB
02_perfect_08.txt AC 13 ms 5836 KiB
03_tree_00.txt AC 16 ms 6668 KiB
03_tree_01.txt AC 18 ms 6584 KiB
03_tree_02.txt AC 16 ms 6532 KiB
03_tree_03.txt AC 17 ms 6588 KiB
03_tree_04.txt AC 17 ms 6600 KiB
03_tree_05.txt AC 18 ms 6472 KiB
03_tree_06.txt AC 18 ms 6612 KiB
04_handmade_00.txt AC 1 ms 3576 KiB
04_handmade_01.txt AC 14 ms 6616 KiB