Pagini recente » Cod sursa (job #2548891) | Cod sursa (job #2752641) | Cod sursa (job #2463784) | Cod sursa (job #2961040)
#include<bits/stdc++.h>
using namespace std;
vector<int> v[50005];
bool seen[50005];
vector<int> solution;
void dfs(int nod)
{
seen[nod] = 1;
for(auto it:v[nod])
{
if(seen[it]) continue;
dfs(it);
}
solution.push_back(nod);
}
int main()
{
ifstream fin("sortaret.in");
ofstream fout("sortaret.out");
int n,m;
fin>>n>>m;
for(int i=1;i<=m;i++)
{
int x,y;
fin>>x>>y;
v[x].push_back(y);
}
for(int i=1;i<=n;i++)
{
if(!seen[i])
dfs(i);
}
reverse(solution.begin(),solution.end());
for(auto it:solution)
fout<<it<<' ';
fout<<'\n';
return 0;
}