Submission #16489054


Source Code Expand

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

struct UnionFind {
  vector<int> d;
  UnionFind(int n=0): d(n,-1) {}
  int find(int x) {
    if (d[x] < 0) return x;
    return d[x] = find(d[x]);
  }
  bool unite(int x, int y) {
    x = find(x); y = find(y);
    if (x == y) return false;
    if (d[x] > d[y]) swap(x,y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  bool same(int x, int y) { return find(x) == find(y);}
  int size(int x) { return -d[find(x)];}
};

int main(void){
    int N, M;
    cin >> N >> M;

    UnionFind union_find = UnionFind(N);

    rep(i, M){
        int A, B;
        cin >> A >> B;
        union_find.unite(A, B);
    }

    int max_group = 0;
    rep(i, N){
        if(union_find.size(i)>max_group){
            max_group = union_find.size(i);
        }
    }

    cout << max_group << endl;


}

Submission Info

Submission Time
Task D - Friends
User papino
Language C++ (GCC 9.2.1)
Score 400
Code Size 889 Byte
Status AC
Exec Time 94 ms
Memory 4028 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 3
AC × 29
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt
All hand_01.txt, hand_02.txt, hand_03.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_11.txt, random_12.txt, random_13.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_31.txt, random_32.txt, random_33.txt, random_41.txt, random_42.txt, random_43.txt, sample_01.txt, sample_02.txt, sample_03.txt
Case Name Status Exec Time Memory
hand_01.txt AC 8 ms 3968 KiB
hand_02.txt AC 2 ms 3576 KiB
hand_03.txt AC 2 ms 3452 KiB
random_01.txt AC 91 ms 3760 KiB
random_02.txt AC 20 ms 3924 KiB
random_03.txt AC 68 ms 3792 KiB
random_04.txt AC 23 ms 3604 KiB
random_05.txt AC 74 ms 3932 KiB
random_06.txt AC 60 ms 3932 KiB
random_07.txt AC 58 ms 3592 KiB
random_08.txt AC 4 ms 4024 KiB
random_11.txt AC 62 ms 3592 KiB
random_12.txt AC 89 ms 3920 KiB
random_13.txt AC 62 ms 3588 KiB
random_21.txt AC 88 ms 3868 KiB
random_22.txt AC 90 ms 3812 KiB
random_23.txt AC 87 ms 3784 KiB
random_24.txt AC 90 ms 3788 KiB
random_25.txt AC 91 ms 4020 KiB
random_26.txt AC 90 ms 4016 KiB
random_31.txt AC 70 ms 3576 KiB
random_32.txt AC 71 ms 3580 KiB
random_33.txt AC 72 ms 3404 KiB
random_41.txt AC 93 ms 3956 KiB
random_42.txt AC 94 ms 4028 KiB
random_43.txt AC 91 ms 3928 KiB
sample_01.txt AC 9 ms 3500 KiB
sample_02.txt AC 2 ms 3592 KiB
sample_03.txt AC 3 ms 3516 KiB