-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathm.cpp
More file actions
78 lines (67 loc) · 1.52 KB
/
m.cpp
File metadata and controls
78 lines (67 loc) · 1.52 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
#include <bits/stdc++.h>
using namespace std;
int n, m, q, u, v, s;
int lst[100001];
bool visited[100001];
int ans[100001];
void bfs(int start, vector<vector<int>> &nodes){
vector<int> checked;
checked.clear();
int ssuk = 0, chung = 0;
queue<int> q;
q.push(start);
visited[start] = true;
if (lst[start] == 1) chung++;
else if (lst[start] == 0) ssuk++;
while(!q.empty()){
int now = q.front();
q.pop();
for (int j=0; j<nodes[now].size(); j++){
int next = nodes[now][j];
if (!visited[next]){
if (lst[next] == 1) chung++;
if (lst[next] == 0) ssuk++;
q.push(next);
visited[next] = true;
checked.push_back(next);
}
}
}
if (chung > ssuk){
ans[start] = 1;
for (int k=0; k<checked.size(); k++){
ans[checked[k]] = 1;
}
}
else{
ans[start] = 0;
for (int k=0; k<checked.size(); k++){
ans[checked[k]] = 0;
}
}
}
int main(void){
fill(ans, ans + 100001, -1);
scanf("%d %d %d", &n, &m, &q);
for (int i=1; i<=n; i++){
scanf("%d", &lst[i]);
}
vector<vector<int>> nodes(n + 1, vector<int> ());
for (int i=0; i<m; i++){
scanf("%d %d", &u, &v);
if (find(nodes[u].begin(), nodes[u].end(), v) == nodes[u].end()){
nodes[u].push_back(v);
nodes[v].push_back(u);
}
}
for (int i=0; i<q; i++){
scanf("%d", &s);
if (ans[s] != -1) printf("%d\n", ans[s]);
else {
memset(visited, false, sizeof(visited));
bfs(s, nodes);
printf("%d\n", ans[s]);
}
}
return 0;
}