Pagini recente » Cod sursa (job #2727480) | Cod sursa (job #915641) | Cod sursa (job #3152438) | Cod sursa (job #440417) | Cod sursa (job #2197511)
#include <fstream>
using namespace std;
ifstream cin("sortaret.in");
ofstream cout("sortaret.out");
struct nod{
int val;
nod* next;
};
nod *lista[100005],*sortat;
int n,m,v[100005];
void add(int x,int y)
{
nod *e=new nod;
e->val=x;
e->next=lista[y];
lista[y]=e;
}
void PUSH(int x)
{
nod *e=new nod;
e->val=x;
e->next=sortat;
sortat=e;
}
void DFS(int x)
{
v[x]=1;
nod *e=lista[x];
while(e)
{
if(!v[e->val])
{
DFS(e->val);
}
e=e->next;
}
PUSH(x);
}
int main()
{
cin >> n >> m;
for(int i=1; i<=m; i++)
{
int x,y;
cin >> x >> y;
add(y,x);
}
for(int i=1; i<=n; i++)
{
if(!v[i])
DFS(i);
}
while(sortat)
{
cout << sortat->val << ' ';
sortat=sortat->next;
}
return 0;
}