Pagini recente » Cod sursa (job #590431) | Cod sursa (job #2899307) | Cod sursa (job #1131890) | Cod sursa (job #1519999) | Cod sursa (job #380824)
Cod sursa(job #380824)
#include<stdio.h>
#define dim 101000
struct nod
{
int el;
nod *next;
} *liste[dim],*c,*q;
int n,m;
int i[dim];
void add(int x,int y)
{
nod *p=new nod;
p->el=y;
p->next=liste[x];
liste[x]=p;
}
void read()
{
int x,y;
scanf("%d %d\n",&n,&m);
for(int k=1;k<=m;k++)
{
scanf("%d %d\n",&y,&x);
add(x,y);
i[y]++;
}
}
void addc(int x)
{
nod *p=new nod;
p->el=x;
p->next=c;
c=p;
}
void addq(int x)
{
nod *p=new nod;
p->el=x;
p->next=q;
q=p;
}
void scan(int x)
{
nod *p=liste[x];
while(p)
{
i[p->el]--;
if(i[p->el]==0)
addc(p->el),addq(p->el);
p=p->next;
}
}
void solve()
{
for(int k=1;k<=n;k++)
if(!i[k])
addc(k),addq(k);
while(c)
{
scan(c->el);
c=c->next;
}
}
void afis()
{
while(q)
{
printf("%d ",q->el);
q=q->next;
}
}
int main ()
{
freopen("sortaret.in","r",stdin);
freopen("sortaret.out","w",stdout);
read();
solve();
afis();
return 0;
}