-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqueen.cpp
More file actions
36 lines (32 loc) · 964 Bytes
/
Copy pathqueen.cpp
File metadata and controls
36 lines (32 loc) · 964 Bytes
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 <bits/stdc++.h>
using namespace std;
int main() {
int n; cin >> n;
bool hate;
vector<pair<int, int>> parent_hate(n + 1);
vector<vector<int>> children(n + 1);
vector<int> result;
for (int i = 1; i <= n; i++) {
cin >> parent_hate[i].first >> parent_hate[i].second;
if (parent_hate[i].first == -1) continue;
else children[parent_hate[i].first].push_back(i);
}
for (int i = 1; i <= n; i++) {
if (parent_hate[i].second == 0) continue;
hate = true;
for (int j = 0; j < children[i].size(); j++) {
if (parent_hate[children[i][j]].second == 0) {
hate = false;
break;
}
}
if (hate) result.push_back(i);
}
if (result.size() == 0) cout << -1;
else {
sort(result.begin(), result.end());
for (int i = 0; i < result.size(); i++) {
cout << result[i] << " ";
}
}
}