Pagini recente » Cod sursa (job #2568773) | Cod sursa (job #377475) | Cod sursa (job #2232732) | Cod sursa (job #1785962) | Cod sursa (job #651842)
Cod sursa(job #651842)
#include <fstream>
#define gL 50001
using namespace std;
ifstream in;
ofstream out;
struct graf
{
int nod;
graf *link;
}*g[gL];
int sol[gL];
int use[gL];
inline void add_edge(int x,int y)
{
graf *p=new graf;
p->nod=y;
p->link=g[x];
g[x]=p;
}
inline void DFS(int nod)
{
use[nod]=1;
for(graf *p=g[nod];p;p=p->link)
if(!use[p->nod]) DFS(p->nod);
sol[++sol[0]]=nod;
}
int main()
{
int M,N,x,y;
in.open("sortaret.in");
in>>N>>M;
for(;M--;)
{
in>>x>>y;
add_edge(x,y);
}
in.close();
for(int nod=1;nod<=N;++nod)
if(!use[nod]) DFS(nod);
out.open("sortaret.out");
for(int i=N;i>1;--i) out<<sol[i]<<' ';
out<<sol[1]<<'\n';
out.close();
return 0;
}