-
Notifications
You must be signed in to change notification settings - Fork 0
/
2380.cpp
71 lines (58 loc) · 797 Bytes
/
2380.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
//2380
#include <bits/stdc++.h>
using namespace std;
int bank[100002], sum[100002];
int find(int x)
{
if(bank[x] == x) return x;
return bank[x] = find(bank[x]);
}
void merge(int a, int b)
{
int x, y;
x = find(a);
y = find(b);
if(x == y) return;
else if(x < y)
{
bank[y] = x;
sum[x]+= sum[y];
}
else if(x > y)
{
bank[x] = y;
sum[y] += sum[x];
}
}
int main()
{
int banks, actions;
cin >> banks >> actions;
for(int i = 0; i < banks; i++)
{
bank[i] = i;
sum[i] = 1;
}
while(actions--)
{
char action;
int a, b;
cin >> action >> a >> b;
switch(action)
{
case 'C':
//
if(find(a-1) == find(b-1))
cout << "S\n";
else
cout << "N\n";
break;
//
case 'F':
//
merge(a-1, b-1);
break;
//
}
}
}