-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbishuAndGf.cpp
More file actions
63 lines (48 loc) · 933 Bytes
/
bishuAndGf.cpp
File metadata and controls
63 lines (48 loc) · 933 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
#include<bits/stdc++.h>
using namespace std;
vector<int> G[1001];
int d[1001]={0};
bool visited[1001]={false};
void dfs(int src,int len)
{
d[src]=len;
visited[src]=true;
for(int i=0;i<G[src].size();i++)
{
if(!visited[G[src][i]]){
dfs(G[src][i],len+1);
}
}
}
int main()
{
//freopen("input.txt","r",stdin);
int a,b;
int nodes;
scanf("%d",&nodes);
for(int i=1;i<nodes;i++)
{
scanf("%d%d",&a,&b);
G[a].push_back(b);
G[b].push_back(a);
}
visited[1]=true;
dfs(1,0);
int q;
scanf("%d",&q);
int temp;
//int Q[q];
int minD=9999;
int gf;
for(int i=0;i<q;i++)
{
scanf("%d",&temp);
if(d[temp]<minD)
{
minD=d[temp];
gf=temp;
}
}
printf("%d\n",gf);
return 0;
}