Pagini recente » Cod sursa (job #1538350) | Cod sursa (job #1666622) | Cod sursa (job #919245) | Cod sursa (job #862594) | Cod sursa (job #2382558)
#include <fstream>
#include <iostream>
#include <vector>
using namespace std;
const string FILE_NAME = "sortaret";
const int N_MAX = 50005;
int N;
vector<int> g[N_MAX];
vector<int> sol;
bool viz[N_MAX];
void init() {
ifstream in { FILE_NAME + ".in" };
int m;
in >> N >> m;
while (m--) {
int x, y;
in >> x >> y;
g[x].emplace_back(y);
}
}
void solve(int node) {
viz[node] = true;
for (const auto& next : g[node])
if (!viz[next])
solve(next);
sol.emplace_back(node);
}
void print() {
ofstream out { FILE_NAME + ".out" };
for (auto it = sol.rbegin(); it != sol.rend(); ++it)
out << *it << ' ';
}
int main() {
init();
solve(1);
print();
}