You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
932 B

#include <bits/stdc++.h>
using namespace std;
const int N = 520;
int g[N][N]; // 路径
int in[N]; // 入度
int ans[N];
int n, m;
/*
4 3
1 2
2 3
4 3
1 2 4 3
*/
void toposort() {
for (int i = 1; i <= n; i++) {
int k = 1;
while (in[k] != 0) k++;
ans[i] = k;
in[k] = -1;
for (int j = 1; j <= n; j++) {
if (g[k][j])
in[j]--;
}
}
}
void init() {
memset(in, 0, sizeof in);
memset(ans, 0, sizeof ans);
memset(g, 0, sizeof g);
}
int main() {
while (~scanf("%d%d", &n, &m)) {
init();
while (m--) {
int x, y;
cin >> x >> y;
if (g[x][y]) continue;
g[x][y] = 1;
in[y]++;
}
toposort();
for (int i = 1; i < n; i++) cout << ans[i] << " ";
cout << ans[n] << endl;
}
return 0;
}