hdu 1285
#include<stdio.h>
#include<string.h>
#define N 600
int map[N][N],indegree[N],n,m;
void judge() {
int k,i,j,flag=0;
for(k=1;k<=n;k++)
for(i=1;i<=n;i++) {
if(indegree[i])continue;
indegree[i]--;
if(flag==0) {
flag=1;
printf("%d",i);
}
else
printf(" %d",i);
for(j=1;j<=n;j++)
if(map[i][j])
indegree[j]--;
break;
}
printf("\n");
}
int main() {
int a,b;
while(scanf("%d%d",&n,&m)!=EOF) {
memset(map,0,sizeof(map));
memset(indegree,0,sizeof(indegree));
while(m--) {
scanf("%d%d",&a,&b);
if(!map[a][b]) {
map[a][b]=1;
indegree[b]++;
}
}
judge();
}
return 0;
}
#include<string.h>
#define N 600
int map[N][N],indegree[N],n,m;
void judge() {
int k,i,j,flag=0;
for(k=1;k<=n;k++)
for(i=1;i<=n;i++) {
if(indegree[i])continue;
indegree[i]--;
if(flag==0) {
flag=1;
printf("%d",i);
}
else
printf(" %d",i);
for(j=1;j<=n;j++)
if(map[i][j])
indegree[j]--;
break;
}
printf("\n");
}
int main() {
int a,b;
while(scanf("%d%d",&n,&m)!=EOF) {
memset(map,0,sizeof(map));
memset(indegree,0,sizeof(indegree));
while(m--) {
scanf("%d%d",&a,&b);
if(!map[a][b]) {
map[a][b]=1;
indegree[b]++;
}
}
judge();
}
return 0;
}