Pagini recente » Cod sursa (job #2729614) | Rating Ada Birtocian (adabirtocian) | Rating Crainiciuc Calin (bloxorz51) | Cod sursa (job #1298178) | Cod sursa (job #2057911)
#define NN 50002
#include <fstream>
#include <vector>
using namespace std;
ifstream in("sortaret.in");
ofstream out("sortaret.out");
vector<int>topo;
vector<int>::iterator it;
struct nod{
int info;
nod *next;
}*L[NN];
void adaug(int x, int y)
{
nod *aux = new nod;
aux -> info = y;
aux -> next = L[x];
L[x]=aux;
}
int n , m ;
void input()
{
in >> n >> m;
for ( int i = 0 ; i < m ; ++i )
{
int x ,y;
in >> x >>y ;
adaug(x,y);
}
}
bool viz[NN];
void dfs(int NOD)
{
viz[NOD]=true;
for(nod *aux= L[NOD]; aux ; aux = aux-> next)
{
if(!viz[aux->info])dfs(aux->info);
}
topo.push_back(NOD);
}
int main()
{
input();
for(int i = 1 ; i <=n ; ++i)
{
if (!viz[i])dfs(i);
}
for(it = topo.end()-1; it !=topo.begin()-1; --it)
out<< *it << " ";
return 0;
}