欧拉图 CCF2016第六次 送货

时间:2023-03-10 01:09:17
欧拉图 CCF2016第六次 送货
 // 欧拉图 CCF2016第六次 送货
// 思路:
// CCF数据很水。。。。这道题有问题
// 先判连通,再dfs边。
// 应为输出要满足字典序最小,用vector存图,sort一遍,用stack保存答案 #include <bits/stdc++.h>
using namespace std;
#define LL long long
typedef pair<int,int> pii;
const double inf = 123456789012345.0;
const LL MOD =100000000LL;
const int N =1e4+;
#define clc(a,b) memset(a,b,sizeof(a))
const double eps = 1e-;
void fre() {freopen("in.txt","r",stdin);}
void freout() {freopen("out.txt","w",stdout);}
inline int read() {int x=,f=;char ch=getchar();while(ch>''||ch<'') {if(ch=='-') f=-; ch=getchar();}while(ch>=''&&ch<='') {x=x*+ch-'';ch=getchar();}return x*f;} vector<int> g[N];
bool vit[N][N];
bool vis[N];
int d[N];
void dfs(int x){
vis[x]=true;
for(int i=;i<(int)g[x].size();i++){
int v=g[x][i];
if(!vis[v])
dfs(v);
}
}
stack<int> st;
void euler(int x){
for(int i=;i<(int)g[x].size();i++){
int v=g[x][i];
if(!vit[x][v]){
vit[x][v]=vit[v][x]=true;
euler(v);
st.push(v);
}
}
}
int main(){
int n,m;
scanf("%d%d",&n,&m);
for(int i=;i<=m;i++){
int x,y;
scanf("%d%d",&x,&y);
g[x].push_back(y);
g[y].push_back(x);
d[x]++;d[y]++;
}
dfs();
bool flag=true;
for(int i=;i<=n;i++){
if(!vis[i]){
flag=false;
break;
}
}
if(!flag){
printf("-1\n");
}
else{
int count=;
for(int i=;i<=n;i++){
sort(g[i].begin(),g[i].end());
if(d[i]%) count++;
}
if(count>) printf("-1\n");
else{
printf("");
euler();
while(!st.empty()){
int a=st.top();
st.pop();
printf(" %d",a);
}
printf("\n");
}
}
return ;
}