Pagini recente » Cod sursa (job #1712830) | Cod sursa (job #1146890) | Cod sursa (job #2910856) | Cod sursa (job #2358034) | Cod sursa (job #2759934)
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define all(a) (a).begin(), (a).end()
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define fr first
#define sc second
#define int long long
#define rc(s) return cout<<s,0
#define rcc(s) cout<<s,exit(0)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int nmax = 50005;
int n, m;
vector<int>nod[nmax];
bitset<nmax>viz;
vector<int>st;
void dfs(int s){
viz[s] = 1;
for(auto it : nod[s]){
if(!viz[it]){
dfs(it);
}
}
st.push_back(s);
}
int32_t main(){
ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
freopen("sortaret.in", "r", stdin);
freopen("sortaret.out", "w", stdout);
cin >> n >> m;
for(int i=1;i<=m;i++){
int x, y;
cin >> x >> y;
nod[x].push_back(y);
}
for(int i=1;i<=n;i++){
if(!viz[i]) dfs(i);
}
reverse(all(st));
for(auto it : st){
cout << it << ' ';
}
}
// 1. Solve the problem
// 2. ???
// 3. Profit
// https://www.youtube.com/watch?v=5qap5aO4i9A