Pagini recente » Cod sursa (job #528797) | Autentificare | Borderou de evaluare (job #2699132) | Atasamentele paginii Profil biancaagape | Cod sursa (job #3343530)
#include <fstream>
#include <stack>
#include <vector>
using namespace std;
const int N = 5e4;
vector <int> ls[N + 1];
bool viz[N + 1];
stack <int> stop;
void dfs(int x) {
viz[x] = true;
for (auto y : ls[x]) {
if (!viz[y]) {
dfs(y);
}
}
stop.push(x);
}
int main() {
ifstream in("sortaret.in");
ofstream out("sortaret.out");
int n, m;
in >> n >> m;
for (int i = 0; i < m; i++) {
int x, y;
in >> x >> y;
ls[x].push_back(y);
}
in.close();
for (int i = 1; i < n; i++) {
if (!viz[i]) {
dfs(i);
}
}
while (!stop.empty()) {
out << stop.top() << " ";
stop.pop();
}
out.close();
return 0;
}