Pagini recente » Cod sursa (job #1124755) | Cod sursa (job #2807166) | Cod sursa (job #1878956) | Cod sursa (job #1177030) | Cod sursa (job #1984968)
#include <bits/stdc++.h>
using namespace std;
ifstream f("sortaret.in");
ofstream g("sortaret.out");
struct Nod
{
int info;
Nod *next;
};
stack <int> s;
Nod *lista[50001];
int n, m, x, y, v[500001], k;
bool viz[50001];
void citire()
{
f>>n>>m;
int i, x, y;
for (i = 1; i <= m; i++)
{
f>>x>>y;Nod *p=new Nod;p->next=lista[x];p->info=y;lista[x]=p;
}
}
void DF(int nod)
{
Nod *p;
viz[nod]=true;
for(p=lista[nod];p!=NULL;p=p->next)
if(!viz[p->info]) DF(p->info);
s.push(nod);
}
int main()
{
citire();
for(int i=1;i<=n;i++)
if(!viz[i]) DF(i);
while(!s.empty())
{
g<<s.top()<<' ';s.pop();
}
f.close();g.close();
return 0;
}