Pagini recente » Cod sursa (job #1793799) | Cod sursa (job #2282267) | Cod sursa (job #531137) | Cod sursa (job #364178) | Cod sursa (job #2560741)
#include <bits/stdc++.h>
using namespace std;
ifstream in("t.in");
ofstream out("t.out");
const int Nmax = 1e5 + 5;
bool vis[Nmax];
stack <int> S;
vector <int> G[Nmax];
void dfs(int node) {
S.push(node);
while(!S.empty()) {
int x = S.top();
if(G[x].empty()) {
ans.push_back(x);
S.pop();
} else {
int y = G[x].back();
G[x].pop_back();
S.push(y);
G[y].erase(find(G[y].begin(),G[y].end(),x));
}
}
}
int main() {
int N,M;
in >> N >> M;
int x,y;
while(M--) {
in >> x >> y;
G[x].push_back(y);
G[y].push_back(x);
}
dfs(1);
return 0;
}