Pagini recente » Cod sursa (job #1900353) | Monitorul de evaluare | Monitorul de evaluare | Cod sursa (job #1010263) | Cod sursa (job #702425)
Cod sursa(job #702425)
#include<fstream>
#define nmax 50003
#define mmax 100003
using namespace std;
typedef struct nod{
int vf;
nod *next;
}*pNod, NOD;
int n,m;
bool viz[nmax];
pNod a[nmax],first=NULL;
void add(int i,int j){
pNod p = new NOD;
p->vf=j;
p->next = a[i];
a[i] = p;
}
void push(int i){
pNod p = new NOD;
p->vf = i;
p->next = first;
first = p;
}
void DFS(int nod){
viz[nod]=1;
pNod p = new NOD;
for(p=a[nod]; p; p=p->next)
if(!viz[p->vf]) DFS(p->vf);
push(nod);
}
int main(void){
freopen("sortaret.in","r",stdin);
freopen("sortaret.out","w",stdout);
int x,y,i; pNod p = new nod;
scanf("%d %d\n",&n,&m);
while(m--){
scanf("%d %d\n",&x,&y);
add(x,y);
}
for(i=1;i<=n;++i)
if(!viz[i]) DFS(i);
for(p=first; p; p=p->next)printf("%d ",p->vf);
return 0;
}