Pagini recente » Cod sursa (job #124516) | Cod sursa (job #2210930) | Cod sursa (job #163329) | Profil AnDrEwBoY | Cod sursa (job #1976876)
#include <bits/stdc++.h>
using namespace std;
#define NMAX 50002
ifstream fin("sortaret.in");
ofstream fout("sortaret.out");
vector<int> graf[NMAX];
stack<int> stiva;
void DFS(int nod) {
for (auto adj: graf[nod])
DFS(adj);
stiva.push(nod);
}
int main() {
int N, M;
fin >> N >> M;
int x, y;
while (M--) {
fin >> x >> y;
graf[x].push_back(y);
}
DFS(1);
while (!stiva.empty()) {
fout << stiva.top() << " ";
stiva.pop();
}
return 0;
}