Pagini recente » Cod sursa (job #2414932) | Cod sursa (job #1831164) | Cod sursa (job #1780817) | Cod sursa (job #2106003) | Cod sursa (job #2406917)
#include <fstream>
#include <algorithm>
#include <vector>
#define nmax 50001
using namespace std;
ifstream fin("sortaret.in");
ofstream fout("sortaret.out");
vector<int> v[nmax];
int v2[nmax];
int ct2;
int n,m;
int t[nmax];
int viz[nmax];
void read()
{
int x,y;
int i;
fin>>n>>m;
for(i=1; i<=m; i++)
{
fin>>x>>y;
v[x].push_back(y);
}
}
void dfs(int x)
{
viz[x]=1;
v2[++ct2]=x;
int ct=v[x].size();
int i;
for(i=0; i<ct; i++)
{
int val=v[x][i];
if(!viz[val]) { dfs(val);}
}
}
struct nod
{
int n,t;
};
nod nn[nmax];
bool cmp(nod n1,nod n2)
{
return n1.t<n2.t;
}
int main()
{
read();
for(int i=1; i<=n; i++)
if(!viz[i]) {dfs(i);}
for(int i=ct2; i>=1; i--) fout<<v2[i]<<" ";
return 0;
}