题目链接:https://codeforces.com/contest/1143/problem/C
题解:(假图论=-=)对于每个点,其可删除性都是独立的,和其他点没关系,所以...按从小到大的顺序遍历判断每个点是否可删就行了。
code:
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5+5;
vector<int>G[maxn];
int t[maxn];
int main(){
int n;
cin >> n;
int p;
for(int i = 1; i <= n; i++){
cin >> p >> t[i];
if(p != -1) G[p].push_back(i);
}
bool flag = 0;
for(int i = 1; i <= n; i++){
bool cut = 1;
if(t[i] == 0) cut = 0;
for(int j = 0; j < G[i].size(); j++){
int to = G[i][j];
if(t[to] == 0){
cut = 0;
break;
}
}
if(cut){
cout << i << " ";
flag = 1;
}
}
if(!flag) cout << "-1";
cout << endl;
return 0;
}