Pagini recente » Rating Angi Szilamer (A.Szilamer) | Rating ofBritania (lelouch) | Rating Pandelica Lucian (LucianPandelica) | Cod sursa (job #1537518) | Cod sursa (job #3030879)
#include <bits/stdc++.h>
using namespace std;
ifstream fin ("sortaret.in");
ofstream fout("sortaret.out");
const int NMAX = 50005;
int n, m, a, b;
vector<vector<int>> g(NMAX);
vector<bool> viz(NMAX, false);
stack<int> st;
void dfs(int node) {
viz[node] = true;
for (int i : g[node])
if (!viz[i])
dfs(i);
st.push(node);
}
void top_sort() {
for (int i = 1; i <= n; i++)
if (!viz[i])
dfs(i);
}
void write() {
while (!st.empty()) {
fout << st.top() << ' ';
st.pop();
}
}
void read() {
fin >> n >> m;
while (m--) {
fin >> a >> b;
g[a].push_back(b);
}
}
int main() {
read();
top_sort();
write();
return 0;
}