-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathC_Queen.cpp
47 lines (37 loc) · 828 Bytes
/
C_Queen.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
45
46
47
// RunAt - Green
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n;
cin >> n;
vector<vector<int>> children(n+1);
vector<int> respect(n+1);
int rootNode = -1;
// Make adjacency list
for (int i=0; i<n; i++) {
int parent;
cin >> parent >> respect[i+1];
if (parent == -1) continue;
children[parent].push_back(i+1);
}
// DFS
vector<int> res;
for (int i=1; i<=n; i++) {
if (respect[i] == 1) {
bool toRemove = true;
for (auto child: children[i]) {
if (respect[child] == 0) {
toRemove = false;
break;
}
}
if (toRemove) res.push_back(i);
}
}
if (res.size() == 0) {cout << -1 << "\n"; return;}
for (auto e : res) cout << e << " ";
}
int main() {
cin.sync_with_stdio(0); cin.tie(0);
solve();
}