Pagini recente » Cod sursa (job #2156643) | Cod sursa (job #1187384) | Cod sursa (job #2180041) | Cod sursa (job #1825588) | Cod sursa (job #3127041)
/******************************************************************************
Online C++ Compiler.
Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.
*******************************************************************************/
#include <fstream>
#include <vector>
using namespace std;
ifstream fin("sortaret.in");
ofstream fout("sortaret.out");
vector<int>g[100001];
int n, viz[100001],m;
int sorttop[100001],cnt;
void dfs(int x) {
viz[x] = 1;
for(auto y : g[x]) {
if(!viz[y])
dfs(y);
}
sorttop[++cnt]= x;
}
int main()
{
fin >> n>>m;
for(int i = 1,x,y; i <= m; ++i) {
fin >> x >> y;
g[x].push_back(y);
}
dfs(1);
for(int i = cnt; i>=1; --i)
fout << sorttop[i] << " ";
return 0;
}