-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathA1013-2.cpp
More file actions
71 lines (66 loc) · 1.18 KB
/
A1013-2.cpp
File metadata and controls
71 lines (66 loc) · 1.18 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
#include <cstdio>
#include <vector>
using namespace std;
const int MAXN = 1000 + 10;
int N, M, K;
int father[MAXN];
bool visited[MAXN];
vector<int> Adj[MAXN];
int init(){
for(int i = 1; i <= N; ++i){
father[i] = i;
visited[i] = false;
}
}
int findFather(int x){
int a = x;
while(x != father[x]){
x = father[x];
}
while(a != father[a]){
int z = a;
a = father[a];
father[a] = x;
}
return x;
}
void Union(int a, int b){
int faA = findFather(a);
int faB = findFather(b);
if(faA != faB){
father[faA] = faB;
}
}
int main(){
scanf("%d%d%d", &N, &M, &K);
for(int i = 0; i < M; ++i){
int c1, c2;
scanf("%d%d", &c1, &c2);
Adj[c1].push_back(c2);
Adj[c2].push_back(c1);
}
int currentPoint;
for(int i = 0; i < K; ++i){
scanf("%d", ¤tPoint);
init();
for(int j = 1; j <= N; ++j){
for(int k = 0; k < Adj[j].size(); ++k){
int u = j, v = Adj[j][k];
if(u != currentPoint && v != currentPoint){
Union(u, v);
}
}
}
int block = 0;
for(int i = 1; i <= N; ++i){
if(i == currentPoint) continue;
int fa_i = findFather(i);
if(visited[fa_i] == false){
++block;
visited[fa_i] = true;
}
}
printf("%d\n", block-1);
}
return 0;
}