hihocoder1181 欧拉路

http://hihocoder.com/problemset/problem/1181?sid=781098

/* ***********************************************
Author        :devil
Created Time  :2016/4/23 9:48:26
************************************************ */
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <stdlib.h>
using namespace std;
int head[1005],net[10005],to[10005],path[5005],pathsize=0;
bool vis[10005];
void dfs(int pos)
{
    for(int i=head[pos];i!=0;i=net[i])
        if(!vis[i])
        {
            vis[i]=true;
            if(i%2) vis[i+1]=true;
            else vis[i-1]=true;
            dfs(to[i]);
        }
    path[pathsize++]=pos;
}
int main()
{
    //freopen("in.txt","r",stdin);
    int n,m,u,v,pos=0;
    scanf("%d%d",&n,&m);
    for(int i=0;i<m;i++)
    {
        scanf("%d%d",&u,&v);
        to[++pos]=v;
        net[pos]=head[u];
        head[u]=pos;
        to[++pos]=u;
        net[pos]=head[v];
        head[v]=pos;
    }
    dfs(1);
    for(int i=0;i<pathsize;i++)
        printf("%d ",path[i]);
    return 0;
}

 

posted on 2016-04-23 09:49  恶devil魔  阅读(187)  评论(0编辑  收藏  举报

导航