Pagini recente » Cod sursa (job #346147) | Cod sursa (job #1568315) | Cod sursa (job #1507642) | Cod sursa (job #1131997) | Cod sursa (job #1223510)
# include <cstdio>
# include <cstring>
# include <iostream>
# define nmax 50005
using namespace std;
typedef struct node
{
int x;
node *next;
}
*nod;
nod S[nmax];
int Sort[nmax];
int M[nmax];
int N(0);
int read()
{
char c[30];
scanf("%s",c);
int k=strlen(c),p(0);
for (int i=0;i<k;++i) p=p*10+c[i]-'0';
return (p);
}
void add(int x,int y)
{
nod p=new node;
p->x=y;
p->next=S[x];
S[x]=p;
}
void dfs(int x)
{
for (nod p=S[x];p;p=p->next)
if (!M[p->x])
M[p->x]=M[x]+1,dfs(p->x);
Sort[++N]=x;
}
int main()
{
freopen("sortaret.in","r",stdin);
freopen("sortaret.out","w",stdout);
int n=read(),m=read();
while (m--)
{
int x=read(),y=read();
add(x,y);
}
dfs(1);
while (N) printf("%d ",Sort[N]),--N;
printf("\n");
return 0;
}