这题也记录一下,马上就有思路了但是细节改了半天
思路:记录每个点的入度,根据输入的顺序先判断入读是否为0,是的话就遍历这个点所能到的所有节点,并将到达节点的入度减1。
#include<iostream>
#include<string>
#include<stdio.h>
#include<string.h>
#include<vector>
#include<map>
#include<set>
#include<unordered_map>
#include<queue>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long LL;
const int maxn=1010;
vector<int> v[maxn];
bool isvist[maxn];
int main()
{
int index[maxn]={0},indexcopy[maxn]={0};
int m,n;
vector<int> res;
scanf("%d%d",&m,&n);
int a,b;
for(int i=0;i<n;i++){
scanf("%d%d",&a,&b);
v[a].push_back(b);
index[b]++;
}
int k,temp[maxn];
scanf("%d",&k);
for(int i=0;i<k;i++){
memset(isvist,false,sizeof(isvist));
int id=1;
for(int j=1;j<=m;j++){
indexcopy[j]=index[id++];
}
// for(int j=1;j<=m;j++){
// printf("%d ",indexcopy[j]);
// }
int temp,flag=0;
for(int j=1;j<=m;j++){
scanf("%d",&temp);
if(indexcopy[temp]==0){
isvist[temp]=true;
flag++;
for(auto it=v[temp].begin();it!=v[temp].end();it++){
indexcopy[*it]--;
}
}
}
if(flag!=m) res.push_back(i);
}
printf("%d",res[0]);
for(int i=1;i<res.size();i++){
printf(" %d",res[i]);
}
}