Pagini recente » Cod sursa (job #604591) | Cod sursa (job #1853768) | Cod sursa (job #331047) | Cod sursa (job #868933) | Cod sursa (job #1927124)
#include <bits/stdc++.h>
#define maxm 500100
#define maxn 100100
using namespace std;
int N,M,Sz[maxn],St[maxn],st;
bool B[maxn];
map<int,int> G[maxn];
void add(int x,int y){G[x][y]++,G[y][x]++,Sz[x]++,Sz[y]++;}
void del(int x,int y){if(G[x][y] > 0) G[x][y]--,G[y][x]--; if(G[x][y]==0) G[x].erase(y),G[y].erase(x);}
void dfs(int nod){
if(B[nod]) return; B[nod]=1;
for(auto it : G[nod]) dfs(it.first);
}
void euler(int nod){
St[++st] = nod;
while(st){
nod = St[st];
if(G[nod].empty()){
--st;
cout << nod << ' ';
}else{
int son = G[nod].begin()->first;
del(nod,son);
St[++st] = son;
}
}
}
int main() {
ios_base::sync_with_stdio(0);cin.tie(0);
ifstream cin("euler.in");
ofstream cout("euler.out");
cin >> N >> M;
for(int x,y;M--;){
cin >> x >> y;
add(x,y);
}
dfs(1);
for(int i = 1;i<=N;i++) if(Sz[i]%2 || !B[i]) return cout << G[i].size(),0;
euler(1);
}