Pagini recente » Cod sursa (job #140715) | Cod sursa (job #2872606) | Cod sursa (job #2091985) | Cod sursa (job #627506) | Cod sursa (job #3167861)
#include <bits/stdc++.h>
using namespace std;
ifstream f("sortaret.in");
ofstream g("sortaret.out");
const int nmax = 50005;
const int mmax = 100005;
struct arc
{
int x, y;
};
stack<int> St;
vector<arc> A[nmax];
int n, m, fr[nmax];
static inline void topo(int nod)
{
while(A[nod].size())
{
arc k = A[nod].back();
A[nod].pop_back();
if(!fr[k.y])
topo(k.y);
}
St.push(nod);
fr[nod] = 1;
}
int main()
{
f.tie();
f >> n >> m;
for(int i = 1; i <= m; i ++)
{
int x, y;
f >> x >> y;
A[x].push_back({x, y});
}
for(int i = 1; i <= n; i ++)
if(!fr[i])
topo(i);
while(!St.empty())
{
g << St.top() << " ";
St.pop();
}
return 0;
}