-
Notifications
You must be signed in to change notification settings - Fork 1
/
CVE.cpp
63 lines (61 loc) · 1.43 KB
/
CVE.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
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int visited[1000001],M[1000001],cnt=0;
vector < int > V[1000001];
vector <int> G;
vector <int>::iterator it;
void dfsU(int v)
{
visited[v]=1;
int si=V[v].size();
for(int i=0;i<si;i++)
if(!visited[V[v][i]])
dfsU(V[v][i]);
}
void dfs()
{
for(it=G.begin();it!=G.end();++it)
if(!visited[*it])
{
cnt++;
dfsU(*it);
}
}
int main()
{
int n,u,v;
cin>>n;
while(1)
{
string s;
cin>>s;
//cout<<c<<" ";
if( s=="C")
{
scanf("%d%d",&u,&v);
if(M[u]==0)
G.push_back(u);
if(M[v]==0)
G.push_back(v);
M[u]=1;M[v]=1;
V[u].push_back(v);
V[v].push_back(u);
}
else if(s=="Q")
{
scanf("%d%d",&u,&v);
memset(visited,0,sizeof(visited));
cnt=0;
dfs();
cout<<cnt<<endl;
}
else
{
//cout<<c;
break;
return 0;
}
}
return 0;
}