Pagini recente » Cod sursa (job #994386) | Cod sursa (job #653216) | Cod sursa (job #930655) | Cod sursa (job #2281700) | Cod sursa (job #1540855)
// infoarenaDFSnonRec.cpp : Defines the entry point for the console application.
//
//#include "stdafx.h"
#include <fstream>
#include <vector>
#include <stack>
#include <assert.h>
#define MaxN 50005
using namespace std;
ifstream fin("sortaret.in");
ofstream fout("sortaret.out");
int N, M;
vector<int> G[MaxN];
bool visited[MaxN];
stack<int> res;
int max(int a, int b) {
return a > b ? a : b;
}
void dfs(int n) {
visited[n] = true;
for (int i = 0; i < G[n].size(); ++i) {
if (!visited[G[n][i]])
dfs(G[n][i]);
}
res.push(n);
}
int main()
{
fin >> N >> M;
for (int i = 0; i < M; ++i) {
int x, y;
fin >> x >> y;
G[x].push_back(y);
}
for (int i = 1; i <= N; ++i) {
if (!visited[i]) {
dfs(i);
}
}
while (!res.empty()) {
fout << res.top() << ' ';
res.pop();
}
return 0;
}