版权声明:版权声明,使用请说明出处 https://blog.csdn.net/qq_41835683/article/details/88924791
题解,题意都在代码里..
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int maxn=1e5+5;
int s[maxn];
signed main(){
/* On each step you select such a non-root vertex that it does not respect its parent and none of its children respects it.
ci=0, if the vertex i respects its parents, and ci=1, if the vertex i does not respect any of its parents.
*/
int n;cin>>n;
for(int i=1;i<=n;i++){
int x,y;cin>>x>>y;
if(x==-1){
s[i]=1;//for root i;
continue;
}
else{
if(y==0){
s[x]=1;//for skipped
s[i]=1;//for vect i has child no condition
}
}
}
vector<int>ve;
for(int i=1;i<=n;i++){
if(!s[i])ve.push_back(i);
}
if(ve.empty())cout<<"-1"<<endl;
else for(auto it:ve)cout<<it<<" ";
return 0;
}