http://poj.org/problem?id=2230
题意:给出无向图,要求走过所有边两次仅且两次,出发点为1求路径
思路:构造有向图,深搜,记录边的访问情况,输出
#include <cstdio>
#include <cstring>
using namespace std;
const int maxn=10000+5;
struct Edge
{
int next,to;
bool vis;
}e[maxn*10];
int head[maxn],k;
void init()
{
memset(head,0,sizeof(head));
k=1;
}
void addedge(int u,int v)
{
e[k].to=v;
e[k].next=head[u];
e[k].vis=0;
head[u]=k++;
}
void euler(int u)
{
for(int i=head[u];i;i=e[i].next)
{
if(!e[i].vis){
e[i].vis=1;
euler(e[i].to);
}
}
printf("%d\n",u);
}
int main()
{
int n,m;
while(~scanf("%d%d",&n,&m))
{
init();
while(m--)
{
int u,v;
scanf("%d%d",&u,&v);
addedge(u,v);
addedge(v,u);
}
euler(1);
}
return 0;
}