#include <cstdio>
#include <iostream>
#include <cstring>
using namespace std;
int N, M, a, b, num;
bool map[510][510];
int temp[510], ans[510];
int main(){
while(scanf("%d %d", &N, &M)!= EOF){
memset(temp, 0, sizeof(temp));
memset(ans, 0, sizeof(ans));
memset(map, 0, sizeof(map));
num = 0;
for(int i = 1; i <= M; i++){
cin >> a >> b;
if(!map[a][b]){
temp[b] ++;
}
map[a][b] = true;
}
while(num <= N){
int j = 1;
while(temp[j] != 0){
j++;
if(j > N){
break;
}
}
temp[j] = -1;
ans[num] = j;
num++;
for(int i = 1; i <= N; i++){
if(map[j][i]){
map[j][i] = false;
temp[i]--;
}
}
}
for(int i = 0; i < num - 1; i++){
if(i == num - 2){
cout << ans[i] << endl;
break;
}
cout << ans[i] << " ";
}
}
return 0;
}
hdu1285拓扑排序
最新推荐文章于 2021-08-11 22:10:29 发布
