Pagini recente » Cod sursa (job #3138483) | Cod sursa (job #328345) | Cod sursa (job #2758365) | Cod sursa (job #2884337) | Cod sursa (job #1893050)
#include<iostream>
#include<fstream>
using namespace std;
ifstream in("sortaret.in");
ofstream out("sortaret.out");
const int oo=50002;
struct nod{int inf;
nod*urm;};
nod *L[oo];
int viz[oo],n,m,tp[oo],k;
void citire(){
in>>n>>m;
int i,x,y;
nod*p;
for(i=1;i<=m;i++)
{in>>x>>y;
p=new nod;
p->inf=y;
p->urm=L[x];
L[x]=p;
}}
void dfs(int x){
viz[x]=1;
for(nod*p=L[x];p;p=p->urm)
if(!viz[p->inf])dfs(p->inf);
tp[++k]=x;
}
void rez(){
int i;
for(i=1;i<=n;i++)
if(!viz[i])dfs(i);
for(i=n;i>=1;i--)out<<tp[i]<<" ";
}
int main(){
citire();
rez();
in.close();
out.close();
return 0;}