Pagini recente » Cod sursa (job #2444027) | Cod sursa (job #1115494) | Cod sursa (job #2121328) | Cod sursa (job #2182639) | Cod sursa (job #2614722)
#include <bits/stdc++.h>
#define DAU ios::sync_with_stdio(false); fin.tie(0); fout.tie(0);
#define PLEC fin.close(); fout.close(); return 0;
using namespace std;
const string problem("sortaret");
ifstream fin(problem + ".in");
ofstream fout(problem + ".out");
using VI = vector<int>;
using VVI = vector<VI>;
using VB = vector<bool>;
VVI g;
VB viz;
stack<int> st;
inline void DFS(int x) {
for (const int& y : g[x])
if (!viz[y])
viz[y] = true, DFS(y);
st.emplace(x);
}
int n, m, x, y;
int main() {
DAU
fin >> n >> m;
g = VVI(n + 1);
for (int i = 1; i <= m; ++i) {
fin >> x >> y;
g[x].emplace_back(y);
}
viz = VB(n + 1);
for (int i = 1; i <= n; ++i)
if (!viz[i])
viz[i] = true, DFS(i);
while (!st.empty())
fout << st.top() << ' ', st.pop();
PLEC
}