File tree 1 file changed +49
-0
lines changed
1 file changed +49
-0
lines changed Original file line number Diff line number Diff line change
1
+ // link : https://cses.fi/problemset/task/1676/
2
+ #include < bits/stdc++.h>
3
+ using namespace std ;
4
+ #define int long long
5
+ #define mod (int ) (1e9 +7 );
6
+ const int N=1e5 +10 ;
7
+ const int INF=1e18 ;
8
+ int parent[N];
9
+ int sizet[N];
10
+ int n,m;
11
+
12
+ void make (int v){
13
+ parent[v]=v;
14
+ sizet[v]=1 ;
15
+ }
16
+ int find (int v){
17
+ if (parent[v]==v)return parent[v];
18
+ return parent[v]=find (parent[v]);
19
+ }
20
+ int Union (int a,int b){
21
+ a=find (a);
22
+ b=find (b);
23
+ if (a!=b){
24
+ if (sizet[a]<sizet[b]){
25
+ swap (a,b);
26
+ }
27
+ parent[b]=a;
28
+ sizet[a]+=sizet[b];
29
+ }
30
+ return sizet[a];
31
+ }
32
+ signed main () {
33
+ cin>>n>>m;
34
+ int cnm=n;
35
+ int sz=1 ;
36
+ for (int i=1 ;i<=n;i++)make (i);
37
+ for (int i=0 ;i<m;i++){
38
+ int a,b;
39
+ cin>>a>>b;
40
+ if (!(find (a)==find (b))){
41
+ int curr_siz=Union (a,b);
42
+ cnm--;
43
+ sz=max (sz,curr_siz);
44
+ }
45
+ cout<<cnm<<" " <<sz<<endl;
46
+ }
47
+ return 0 ;
48
+ }
49
+
You can’t perform that action at this time.
0 commit comments