-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMafia.cpp
More file actions
81 lines (66 loc) · 1.03 KB
/
Mafia.cpp
File metadata and controls
81 lines (66 loc) · 1.03 KB
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
77
78
79
80
81
#include <iostream>
#include <set>
#include <vector>
#include <algorithm>
#include <math.h>
#include <string>
#include <queue>
using namespace std;
typedef long long LL;
typedef vector<int> vi;
const int MaxN = 100000;
vi g[MaxN+5];
int dist[MaxN+5];
int prv[MaxN+5];
int getMaxDepth(queue<int> &q)
{
while (!q.empty())
{
int v = q.front();
q.pop();
int d = dist[v] + 1;
for (int u : g[v])
if (u != prv[v])
if (dist[u]!=-1)
{
return d - 1;
}
else
{
dist[u] = d;
q.push(u);
prv[u] = v;
}
}
return MaxN;
}
int main() {
int n,m,k;
cin >> n >> m >> k;
for (int i = 0; i <= n; i++)
{
dist[i] = -1;
prv[i] = -1;
}
int u,v;
for (int i = 0; i < m; i++)
{
cin >> u >> v;
g[u].push_back(v);
g[v].push_back(u);
}
queue<int> q;
for (int i = 0; i < k; i++)
{
cin >> v;
q.push(v);
dist[v] = 0;
}
int maxD = getMaxDepth(q);
int ans = 0;
for (int i = 1; i <= n; i++)
if (dist[i] >= 0 && dist[i] <= maxD)
ans++;
cout << ans << endl;
return 0;
}