Pagini recente » Cod sursa (job #935973) | Cod sursa (job #3353053) | Cod sursa (job #623556) | Cod sursa (job #1005745) | Cod sursa (job #3353074)
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;
ifstream fin("sortaret.in");
ofstream fout("sortaret.out");
const int nmax = 50000;
int n,m;
vector <int> v[nmax + 5];
vector <int> s;
bool viz[nmax + 5];
void sort_top(int nod) {
viz[nod] = true;
for (auto &i : v[nod])
if (!viz[i]) sort_top(i);
s.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);
}
for (int i = 1; i <= n; i++)
if (!viz[i]) sort_top(i);
reverse(s.begin(),s.end());
for (auto& i : s)
fout<<i<<' ';
}