Pagini recente » Cod sursa (job #1886346) | Cod sursa (job #1886351) | Cod sursa (job #2202619) | Cod sursa (job #2203970) | Cod sursa (job #2024860)
#include <array>
#include <vector>
#include <fstream>
#include <algorithm>
#include <iterator>
constexpr int MAX_VERTEX=50011;
std::vector<int> order;
std::vector<int> G[MAX_VERTEX];
std::array<bool, MAX_VERTEX> was;
void dfs(int x) {
was[x] = true;
for (auto y: G[x]) {
if (!was[y]) {
dfs(y);
}
}
order.push_back(x);
}
int main() {
int N, M;
std::ifstream in{"sortaret.in"};
std::ofstream out{"sortaret.out"};
for (in >> N >> M; M; --M) {
int x, y;
in >> x >> y;
G[x].push_back(y);
}
for (int i = 1; i <= N; ++i) {
if (!was[i]) dfs(i);
}
std::copy(order.rbegin(), order.rend(), std::ostream_iterator<int>{out, " "});
return 0;
}