Pagini recente » Cod sursa (job #1885025) | Cod sursa (job #1610951) | Cod sursa (job #235670) | Cod sursa (job #1863192) | Cod sursa (job #1540849)
// infoarenaDFSnonRec.cpp : Defines the entry point for the console application.
//
//#include "stdafx.h"
#include <fstream>
#include <vector>
#include <stack>
#include <assert.h>
#define MaxN 50000
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);
G[y].push_back(x);
}
for (int i = 1; i <= N; ++i) {
if (!visited[i]) {
dfs(i);
}
}
while (!res.empty()) {
fout << res.top() << ' ';
res.pop();
}
return 0;
}