Pagini recente » Cod sursa (job #1546508) | Cod sursa (job #371197) | Cod sursa (job #1768392) | Cod sursa (job #2304776) | Cod sursa (job #3241814)
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;
ifstream fin("sortaret.in");
ofstream fout("sortaret.out");
int n,m;
const int sz = 50000;
vector <int> v[sz + 5];
bool viz[sz + 5];
vector <int> stk;
void top(int nod)
{
viz[nod]=true;
for(auto& i : v[nod]) if(!viz[i]) top(i);
stk.push_back(nod);
}
int main()
{
fin>>n>>m;
for(int i=1;i<=m;i++)
{
int x,y;
fin>>x>>y;
v[x].push_back(y);
}
top(1);
reverse(stk.begin(),stk.end());
for(auto& i : stk) fout<<i<<' ';
}