Submission #37800101


Source Code Expand

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y);
#define chmin(x,y) x = min(x,y);
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, -1, 0, 1};
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const double PI = acos(-1);



int main() {
    int n, m;
    cin >> n >> m;
    dsu d(n);
    rep(i,m) {
        int u, v;
        cin >> u >> v;
        u--; v--;
        d.merge(u, v);
    }
    int ans = 0;
    rep(i,n) {
        if (d.leader(i) == i) ans++;
    }
    cout << ans << endl;
    return 0;
}

Submission Info

Submission Time
Task C - Count Connected Components
User taki0711
Language C++ (GCC 9.2.1)
Score 300
Code Size 727 Byte
Status AC
Exec Time 7 ms
Memory 3636 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 300 / 300
Status
AC × 3
AC × 20
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, 02_corner_00.txt, 02_corner_01.txt, 02_corner_02.txt, 03_path_00.txt, 04_perfect_00.txt, 05_m_eq_0_00.txt, 06_n_eq_1_00.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 7 ms 3608 KiB
00_sample_01.txt AC 2 ms 3628 KiB
00_sample_02.txt AC 2 ms 3468 KiB
01_random_00.txt AC 2 ms 3560 KiB
01_random_01.txt AC 2 ms 3628 KiB
01_random_02.txt AC 2 ms 3636 KiB
01_random_03.txt AC 2 ms 3636 KiB
01_random_04.txt AC 2 ms 3448 KiB
01_random_05.txt AC 2 ms 3600 KiB
01_random_06.txt AC 5 ms 3476 KiB
01_random_07.txt AC 4 ms 3596 KiB
01_random_08.txt AC 2 ms 3500 KiB
01_random_09.txt AC 2 ms 3492 KiB
02_corner_00.txt AC 2 ms 3520 KiB
02_corner_01.txt AC 2 ms 3468 KiB
02_corner_02.txt AC 2 ms 3600 KiB
03_path_00.txt AC 2 ms 3528 KiB
04_perfect_00.txt AC 5 ms 3536 KiB
05_m_eq_0_00.txt AC 3 ms 3456 KiB
06_n_eq_1_00.txt AC 2 ms 3596 KiB