-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfandf.cpp
More file actions
executable file
·76 lines (55 loc) · 1020 Bytes
/
fandf.cpp
File metadata and controls
executable file
·76 lines (55 loc) · 1020 Bytes
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
72
73
74
75
76
#include <bits/stdc++.h>
using namespace std;
#define ll unsigned long long int
#define SIZE 2000000
#define ft first
#define sd second
#define pb push_back
ll mod = 1000000007;
ll root[SIZE], size[SIZE];
ll getroot(ll u)
{
while(root[u]!=u)
{
root[u]=root[root[u]];
u = root[u];
}
return u;
}
void unionNodes(ll u, ll v)
{
ll r_u=getroot(u);
ll r_v=getroot(v);
if(size[r_u]>size[r_v])
{
root[r_v]=root[r_u];
size[r_u]+=size[r_v];
size[r_v]=0;
}
else
{
root[r_u]=root[r_v];
size[r_v]+=size[r_u];
size[r_u]=0;
}
return;
}
int main(void)
{
ll n, ans=0, u, v, q2, q1;
cin>>n;
map<int,int> mp;
for(int i=0; i<n; i++){ root[i]=i; size[i]=1; }
cin>>q1;
for(ll i=0; i<q1; i++){ cin>>u>>v; unionNodes(u-1, v-1); }
for(ll i=0; i<n; i++) mp[getroot(i)]++;
cin>>q2;
for(ll j=0; j<q2; j++){
cin>>u>>v;
u-=1; v-=1;
if(getroot(u)==getroot(v)) size[getroot(u)]=0;
}
for(int i=0; i<n; i++) ans=max(ans, size[i]);
cout<<ans<<"\n";
return 0;
}