phlingoo
Giới thiệu
include<bits/stdc++.h>
using namespace std;
vector<int> p,sl, mx;
void init(int n) {
p.resize(n+1);
sl.resize(n+1);
mx.resize(n+1);
for (int i=1; i<=n; i++){
p[i] = i;
sl[i]= 1;
mx[i]=i;
}
}
int find (int a) {
if (a == p[a]) return a;
return p[a]=find(p[a]);
}
void union_set (int a, int b) {
a = find(a);
b = find(b);
if (p[a]>p[b]) {
swap(a,b);
p[a]+= p[b];
p[b] = a;
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
int n,m;
cin>> n>> m;
init(n);
int tg =n;
while (m--){
int a,b;
cin>> a>> b;
if (union_set(a, b)) {
sl = max(sl, p.size(a));
tg--;
}
cout<< tg << ' ' << sl << '\n';
}
return 0;
}