-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSOCNETC.cpp
71 lines (58 loc) · 1.01 KB
/
SOCNETC.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include<bits/stdc++.h>
using namespace std;
struct rec{
int par,size;
};
rec data[100002];
int parent(int x){
while(data[x].par != x)
x = data[x].par;
return x;
}
void unite(int x,int y,int m){
int px = parent(x);
int py = parent(y);
if(px != py && data[px].size + data[py].size <= m){
if(data[px].size <= data[py].size){
data[px].par = py;
data[py].size += data[px].size;
}else{
data[py].par = px;
data[px].size += data[py].size;
}
}
}
int get_size(int x){
int px = parent(x);
// cout<<"parent = "<<px<<"\t"<<data[px].size<<"\n";
return data[px].size;
}
int main(){
freopen("in.txt","r",stdin);
int n,m,q;
cin>>n>>m>>q;
for(int i=1;i<=n;i++){
data[i].size = 1;
data[i].par = i;
}
while(q--){
char a;
int x,y;
cin>>a;
if(a == 'A'){
cin>>x>>y;
unite(x,y,m);
}else if(a == 'E'){
cin>>x>>y;
if(parent(x) == parent(y)){
cout<<"Yes\n";
}else{
cout<<"No\n";
}
}else if(a == 'S'){
cin>>x;
cout<<get_size(x)<<"\n";
}
}
return 0;
}