-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtelephone.cpp
44 lines (40 loc) · 976 Bytes
/
telephone.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
37
38
39
40
41
42
43
44
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <assert.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
vector<vector<int>> cts(k);
vector<int> cows(n);
for (int i=0; i<n; i++) {
int a; cin >> a; a--;
cts[a].push_back(i);
cows[i] = a;
}
vector<vector<bool>> good(n, vector<bool>(n));
for (int i=0; i<k; i++) {
for (int j=0; j<k; j++) {
char c; cin >> c;
good[i][j] = (c == '1');
}
}
vector<vector<int>> adj(n);
for (int i=0; i<n; i++) {
int cur = cows[i];
for (int j=0; j<k; j++) {
if (good[cur][j]) {
adj[i].insert(adj[i].end(), cts[j].begin(), cts[j].end());
}
}
}
for (int i=0; i<n; i++) {
cout << 1+i << ": ";
for (int j=0; j<adj[i].size(); j++) {
cout << adj[i][j]+1 << ",";
}
cout << '\n';
}
}