拓扑排序
作者:互联网
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<bitset>
#include<ctime>
using namespace std;
const int N=105;
int n,m,x,y,MAP[N][N],indegree[N];
void toposort(int m){
for(int i=1;i<=m;i++){
for(int j=1;j<=m;j++){
if(indegree[j]==0){
indegree[j]--;
cout<<j<<" ";
for(int k=1;k<=m;k++){
if(MAP[j][k]==1){
indegree[k]--;
}
}
break;
}
}
}
}
int main(){
scanf("%d%d",&m,&n);
memset(MAP,0,sizeof(MAP));
memset(indegree,0,sizeof(indegree));
for(int i=1;i<=n;i++){
scanf("%d%d",&x,&y);
if(!MAP[x][y]){
MAP[x][y]=1;
indegree[y]++;
}
}
toposort(m);
return 0;
}
标签:std,MAP,排序,const,int,拓扑,include,toposort 来源: https://www.cnblogs.com/ukcxrtjr/p/11194345.html