Pagini recente » Cod sursa (job #952498) | Cod sursa (job #1852800) | Cod sursa (job #1714651) | Cod sursa (job #1274327) | Cod sursa (job #765744)
Cod sursa(job #765744)
#include <fstream>
using namespace std;
const int NMAX=50007;
ifstream in("sortaret.in");
ofstream out("sortaret.out");
struct nod
{
int data;
nod *next;
}*V[NMAX];
bool Uz[NMAX];
int ST[NMAX],Vf;
int N,M;
void Add(int x,int y)
{
nod *aux = new nod;
aux->next = V[x];
aux->data = y;
V[x] = aux;
}
void Push(int x)
{
ST[++Vf] = x;
}
void DFS(int x)
{
Uz[x] = 1;
int y;
nod *cont = new nod;
for(cont = V[x];cont!=NULL;cont=cont->next)
{
y = cont->data;
if(!Uz[y])
DFS(y);
}
Push(x);
}
int main()
{
int x,y;
in>>N>>M;
while(M--)
{
in>>x>>y;
Add(x,y);
//Add(y,x);
}
for(x=1;x<=N;x++)
if(!Uz[x])
DFS(x);
while(Vf)
out<<ST[Vf--]<<' ';
out.close();
return 0;
}