-
Notifications
You must be signed in to change notification settings - Fork 2
/
1112.cpp
36 lines (31 loc) · 837 Bytes
/
1112.cpp
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
#include <cstdio>
#include <queue>
using namespace std;
int index[100005], relation[1005][1005], level[1005];
bool known[1005];
priority_queue<int> pri_que;
int main() {
int n, k; scanf("%d%d", &n, &k);
for (int i = 1; i <= n; ++i) {
scanf("%d", &level[i]);//level[i]第i个人的知识水平
index[level[i]] = i;//知识水平为level[i]的人的编号
}
for (int i = 1; i <= k; ++i) {
int id; scanf("%d", &id);
known[id] = true; pri_que.push(level[id]);
}
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= n; ++j)
scanf("%d", &relation[i][j]);
while (!pri_que.empty()) {
int asked_index = index[pri_que.top()];
printf("%d\n", asked_index);
pri_que.pop();
for (int i = 1; i <= n; ++i)
if (relation[i][asked_index] && !known[i]) {
pri_que.push(level[i]);
known[i] = true;
}
}
return 0;
}