-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path1076.cpp
More file actions
47 lines (45 loc) · 875 Bytes
/
1076.cpp
File metadata and controls
47 lines (45 loc) · 875 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
#include<bits/stdc++.h>
using namespace std;
const int oo=0x3f3f3f3f;
vector<vector<int> > g;
int vis[1000];
int cc=0;
set<int>valores;
void dfs(int u)
{
vis[u]=1;
for(int i=0;i<g[u].size();i++)
{
int q=g[u][i];
if(vis[q]==0)
{
dfs(q);
cc++;
}
}
}
int main()
{
int n;cin >> n;
while(n--)
{
memset(vis,0,sizeof vis);
int ini;cin >> ini;
int v,a;cin >> v >> a;
g.assign(v,vector<int>());
for(int i=0;i<a;i++)
{
int x,y;cin >> x >> y;
valores.insert(x);
valores.insert(y);
g[x].push_back(y);
g[y].push_back(x);
}
if(valores.find(ini)!=valores.end())dfs(ini);
else cc=0;
printf("%d\n",cc*2);
valores.clear();
cc=0;
}
return 0;
}