Pagini recente » Cod sursa (job #596783) | Cod sursa (job #118734) | Cod sursa (job #2076442) | Statistici Mihnea Nuconteaza (mihneainfo) | Cod sursa (job #1463679)
#include <fstream>
#include <vector>
using namespace std;
ifstream cin("sortaret.in");
ofstream cout("sortaret.out");
#define Nmax 100013
class cell {
public :
int node;
cell *prev;
cell (int a, cell *l) {node=a; prev=l;};
};
class UndirectedGraph {
private :
cell *adj[Nmax];
bool used[Nmax];
public :
vector <int> TopSort;
int dfs(int node){
used[node]=1;
for (cell *it = adj[node];it;it=it->prev)
if (!used[it->node])
dfs(it->node);
TopSort.push_back(node);
return 1;
}
void addEdge(int a,int b){
cell *aux = new cell(b,adj[a]); adj[a]=aux;
aux = new cell(a,adj[b]); adj[b]=aux;
}
} Graph;
int n,m,a,b;
int main(void) {
cin>>n>>m;
while(m--) {
cin>>a>>b;
Graph.addEdge(a,b);
}
Graph.dfs(1);
vector <int>::iterator it;
for (it=Graph.TopSort.end()-1;it!=Graph.TopSort.begin()-1;--it)
cout<<*it<<" ";
return 0;
}