Pagini recente » Cod sursa (job #527037) | Cod sursa (job #859816) | Cod sursa (job #2077559) | Cod sursa (job #579419) | Cod sursa (job #2175401)
#include <fstream>
#include <algorithm>
#include <vector>
#include <stack>
using namespace std;
ifstream fin("euler.in");
ofstream fout("euler.out");
const int NMAX=100000;
int n, m, node;
bool use[NMAX+5];
vector<int>G[NMAX+5];
stack<int>st;
void euler(int node)
{
while(!G[node].empty())
{
st.push(node);
int other=G[node].back();
G[node].pop_back();
G[other].erase(find(G[other].begin(), G[other].end(), node));
node=other;
}
}
int main()
{
int i, x, y;
fin>>n>>m;
for(i=1;i<=m;i++)
{
fin>>x>>y;
G[x].push_back(y);
G[y].push_back(x);
}
node=1;
do
{
euler(node);
node=st.top();
fout<<node<<" ";
st.pop();
}while(!st.empty());
return 0;
}