Submission #73711914


Source Code Expand

#include <bits/stdc++.h>
using namespace std;

#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
#endif

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define fix(x) fixed << setprecision(x)
#define rep(i, start, end) for (auto i = (start); (i) < (end); (i)++)
#define repe(i, start, end) for (auto i = (start); (i) <= (end); (i)++)
#define rrep(i, start, end) for (auto i = (start); (i) >= (end); (i)--)

constexpr auto PI = 3.14159265358979;
constexpr int INF = 1e+9;
constexpr long long INFL = 1e+18;

using ll = long long;
using lld = long double;
// using mint = modint1000000007;
using mint = modint998244353;
using Pair_int = pair<int, int>;
using Pair_ll = pair<ll, ll>;
template <class T>
using Graph = vector<vector<T>>;

template <class T1, class T2>
inline auto div_floor(T1 a, T2 b)
{
    if (b < 0)
        a *= -1, b *= -1;
    if (a >= 0)
        return a / b;
    else
        return (a + 1) / b - 1;
}
template <class T1, class T2>
inline auto div_ceil(T1 a, T2 b)
{
    if (b < 0)
        a *= -1, b *= -1;
    if (a <= 0)
        return a / b;
    else
        return (a - 1) / b + 1;
}
ll floor_sqrt(ll x)
{
    ll y = sqrt(x);
    while (y * y > x)
        y--;
    while ((y + 1) * (y + 1) <= x)
        y++;
    return y;
}
ll pow_int(ll x, ll n)
{
    ll res = 1;
    while (n > 0)
    {
        if (n & 1)
            res *= x;
        x *= x;
        n >>= 1;
    }
    return res;
}
ll pow_mod(ll x, ll n, ll mod)
{
    ll res = 1;
    while (n > 0)
    {
        if (n & 1)
            res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}
ll gcd(ll x, ll y)
{
    if (x < y)
        swap(x, y);
    ll r;
    while (y > 0)
    {
        r = x % y;
        x = y;
        y = r;
    }
    return x;
}
ll lcm(ll x, ll y) { return ll(x / gcd(x, y)) * y; }
ll nCk(ll n, ll r)
{
    if (r < 0 || n < r)
        return 0;
    ll ans = 1;
    for (ll i = 1; i <= r; i++)
    {
        ans *= n--;
        ans /= i;
    }
    return ans;
}
int get_rand(int seed, int min, int max)
{
    static mt19937_64 mt64(seed);
    uniform_int_distribution<int> get_rand_int(min, max);
    return get_rand_int(mt64);
}
template <typename T>
inline bool chmax(T &a, T b) { return ((a < b) ? (a = b, true) : (false)); }
template <typename T>
inline bool chmin(T &a, T b) { return ((a > b) ? (a = b, true) : (false)); }
template <class T1, class T2>
inline auto mod(T1 x, T2 r) { return (x % r + r) % r; }

// ======================================== //

int main()
{
    int N, M;
    cin >> N >> M;
    vector<Pair_int> edges(M);
    rep(i, 0, M)
    {
        int U, V;
        cin >> U >> V;
        U--, V--;
        edges[i] = {U, V};
    }

    dsu uf(N);
    int cnt = N;
    rrep(i, M - 1, 0)
    {
        if (cnt <= 2)
            break;

        if (!uf.same(edges[i].first, edges[i].second))
        {
            uf.merge(edges[i].first, edges[i].second);
            cnt--;
        }
    }

    mint ans = 0;
    mint pow2 = 2;
    rep(i, 0, M)
    {
        if (!uf.same(edges[i].first, edges[i].second))
        {
            ans += pow2;
        }
        pow2 *= 2;
    }

    cout << ans.val() << endl;

    return 0;
}

Submission Info

Submission Time
Task E - Divide Graph
User Yuulis
Language C++23 (GCC 15.2.0)
Score 475
Code Size 3244 Byte
Status AC
Exec Time 77 ms
Memory 5712 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 3632 KiB
00_sample_01.txt AC 1 ms 3580 KiB
00_sample_02.txt AC 1 ms 3452 KiB
01_random_00.txt AC 49 ms 4788 KiB
01_random_01.txt AC 43 ms 4536 KiB
01_random_02.txt AC 37 ms 4356 KiB
01_random_03.txt AC 4 ms 3580 KiB
01_random_04.txt AC 45 ms 4564 KiB
01_random_05.txt AC 39 ms 4228 KiB
01_random_06.txt AC 32 ms 4276 KiB
01_random_07.txt AC 31 ms 4176 KiB
01_random_08.txt AC 47 ms 4552 KiB
01_random_09.txt AC 33 ms 4280 KiB
01_random_10.txt AC 73 ms 5380 KiB
01_random_11.txt AC 71 ms 5456 KiB
01_random_12.txt AC 75 ms 5508 KiB
01_random_13.txt AC 47 ms 4680 KiB
01_random_14.txt AC 65 ms 5428 KiB
02_perfect_00.txt AC 50 ms 4732 KiB
02_perfect_01.txt AC 50 ms 4812 KiB
02_perfect_02.txt AC 50 ms 4808 KiB
02_perfect_03.txt AC 50 ms 4808 KiB
02_perfect_04.txt AC 50 ms 4816 KiB
02_perfect_05.txt AC 50 ms 4796 KiB
02_perfect_06.txt AC 50 ms 4800 KiB
02_perfect_07.txt AC 50 ms 4920 KiB
02_perfect_08.txt AC 50 ms 4808 KiB
03_tree_00.txt AC 73 ms 5696 KiB
03_tree_01.txt AC 77 ms 5708 KiB
03_tree_02.txt AC 71 ms 5704 KiB
03_tree_03.txt AC 76 ms 5712 KiB
03_tree_04.txt AC 76 ms 5704 KiB
03_tree_05.txt AC 76 ms 5572 KiB
03_tree_06.txt AC 77 ms 5636 KiB
04_handmade_00.txt AC 1 ms 3520 KiB
04_handmade_01.txt AC 72 ms 5572 KiB