Pagini recente » Cod sursa (job #813467) | Cod sursa (job #2967993) | Cod sursa (job #1173829) | Cod sursa (job #2742063) | Cod sursa (job #3167850)
#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[mmax];
static inline sorttop(int nod)
{
while(A[nod].size())
{
arc k = A[nod].back();
A[nod].pop_back();
sorttop(k.y);
}
St.push(nod);
}
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});
}
sorttop(1);
while(!St.empty())
{
g << St.top() << " ";
St.pop();
}
return 0;
}