【链接】 我是链接,点我呀:)
【题意】
在这里输入题意
【题解】
拓扑大水题
【代码】
#include <bits/stdc++.h>
using namespace std;
const int N = 100;
int n,m;
int du[N+10];
vector <int> g[N+10];
queue <int> dl;
int main(){
// freopen("rush.txt","r",stdin);
while (~scanf("%d%d",&n,&m)){
if (n==0 && m==0) break;
while (!dl.empty()) dl.pop();
for (int i = 1;i <= N;i++) g[i].clear(),du[i] = 0;
for (int i = 1;i <= m;i++){
int x,y;
scanf("%d%d",&x,&y);
g[x].push_back(y);
du[y]++;
}
for (int i = 1;i <= n;i++)
if (du[i]==0){
dl.push(i);
du[i] = -1;
}
vector <int> v;
while (!dl.empty()){
int x = dl.front();
v.push_back(x);
dl.pop();
for (int y:g[x]){
du[y]--;
if (du[y]==0){
du[y] = -1;
dl.push(y);
}
}
}
int first = 1;
for (int x:v){
if (!first) putchar(' ');
first = 0;
printf("%d",x);
}
puts("");
}
return 0;
}