Pagini recente » Cod sursa (job #2326819) | Cod sursa (job #173429) | Cod sursa (job #2736483) | Cod sursa (job #1649587) | Cod sursa (job #2084279)
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
inline void debugMode() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("sortaret.in", "r", stdin);
freopen("sortaret.out", "w", stdout);
#endif // ONLINE_JUDGE
}
inline void PrintYes() { cout << "Yes"; }
inline void PrintNo() { cout << "No"; }
const double eps = 1e-7;
const int Nmax = 5e5 + 10;
int N, M;
vector< int > G[Nmax];
bool viz[Nmax];
stack< int > solutie;
void DFS(int node)
{
viz[node] = true;
for(auto it: G[node])
if(viz[it] == false)
DFS(it);
solutie.push(node + 1);
}
int main()
{
debugMode();
cin >> N >> M;
for(int i = 1; i <= M; ++i) {
int x, y;
cin >> x >> y;
G[x - 1].push_back(y - 1);
}
for(int i = 1; i <= N; ++i)
if(viz[i - 1] == false)
DFS(i - 1);
while(!solutie.empty()) {
cout << solutie.top() << " ";
solutie.pop();
}
return 0;
}