poj 2230——Watchcow
2014-07-22 09:49
218 查看
题意:给出一个无向图,要求求出一个路径使得走过每条路正反两遍
思路:求有向图的欧拉路径
代码如下:
思路:求有向图的欧拉路径
代码如下:
#include<cstdio> #include<iostream> #include<cstring> using namespace std; const int maxn=100005; struct Edge { int u,v,next; }edge[maxn]; int tot; int first[maxn]; bool vis[maxn]; void add(int uu,int vv) { edge[tot].u=uu; edge[tot].v=vv; edge[tot].next=first[uu]; first[uu]=tot++; } int ans[maxn]; int rec; void dfs(int now) { for(int k=first[now];k!=-1;k=edge[k].next) { if(!vis[k]) { vis[k]=true; dfs(edge[k].v); ans[rec++]=edge[k].v; } } } int main() { //freopen("data.txt","r",stdin); memset(vis,0,sizeof(vis)); memset(first,-1,sizeof(first)); int m,n; tot=0; rec=0; scanf("%d%d",&n,&m); for(int i=0;i<m;++i) { int u,v; scanf("%d%d",&u,&v); add(u,v); add(v,u); } //ans[rec++]=1; dfs(1); ans[rec++]=1; for(int i=0;i<rec;++i) { printf("%d\n",ans[i]); } return 0; }
相关文章推荐
- poj[2230]Watchcow 深搜 欧拉回路
- POJ 2230 Watchcow 【欧拉回路】
- poj2230 Watchcow
- POJ 2230 Watchcow【有向图的欧拉回路+DFS遍历】
- POJ 2230 Watchcow (欧拉路径 dfs 邻接表)
- POJ 2230 Watchcow
- poj 2230 Watchcow(欧拉回路)
- poj 2230 Watchcow (欧拉回路的应用)
- POJ 2230 Watchcow
- POJ 2230 - Watchcow 输出欧拉回路点的路径...
- POJ 2230 Watchcow (欧拉回路)
- poj_2230 Watchcow
- 【POJ - 2230 Watchcow】 欧拉回路
- poj 2230 Watchcow 无向欧拉回路求路径
- POJ 2230 Watchcow( 欧拉回路 )
- POJ 2230 Watchcow
- poj 2230 Watchcow(欧拉回路)
- POJ 2230 Watchcow 有向图两次欧拉回路记录路径
- POJ2230 Watchcow【欧拉回路】
- POJ 2230 Watchcow 欧拉回路输出解