Pagini recente » Clasamentul arhivei de probleme | Rating Iuliana Rusu (IulianaRusu) | Cod sursa (job #2424009) | Cod sursa (job #217456) | Cod sursa (job #2748530)
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template<typename T>
using oset = tree<T, null_type, less<T>,
rb_tree_tag, tree_order_statistics_node_update>;
#ifdef Wi_TEST
template<typename T1, typename T2>
ostream& operator<<(ostream& out, pair<T1,T2> p) {
out << "(" << p.first << ", " << p.second << ")";
out.flush();
return out;
}
#define deb(x) cout << #x << " = " << x << endl;
#else
#define deb(x)
#define cin fin
#define cout fout
#endif
const long long MOD = 1e9+7;
#define N 50005
vector<int> g[N];
bool viz[N];
vector<int> sol;
void DFS(int x) {
viz[x] = true;
for(int& aux : g[x])
if(!viz[aux])
DFS(aux);
sol.push_back(x);
}
int main() {
ios_base::sync_with_stdio(false);
ifstream fin("sortaret.in");
ofstream fout("sortaret.out");
int n, m, x, y;
cin >> n >> m;
while(m--) {
cin >> x >> y;
g[x].push_back(y);
}
for(int i = 1; i <= n; ++i)
if(!viz[i])
DFS(i);
for(int i = sol.size() - 1; i >= 0; --i)
cout << sol[i] << ' ';
return 0;
}