poj 2230 Watchcow
2015-01-19 10:57
246 查看
poj.org/problem?id=2230
大意是给你一个无向图,要求找一条路径,走过每一条边恰好两次,且每次走的方向不同。很容易就能想到把无向图转化为有向图求欧拉回路。题目保证一定能找到从1点出发回到1点的答案。也就是说只需要深搜找到欧拉路径。
大意是给你一个无向图,要求找一条路径,走过每一条边恰好两次,且每次走的方向不同。很容易就能想到把无向图转化为有向图求欧拉回路。题目保证一定能找到从1点出发回到1点的答案。也就是说只需要深搜找到欧拉路径。
#include <vector> #include <sstream> #include <stdio.h> #include <string.h> #include <iostream> #include <algorithm> using namespace std; const int V = 10010; const int E = 100010; int n,m; int cnt,head[V],path[V],top; struct edge{ int u,v,next; bool vis; }node[E]; void Init(){ cnt = 0; top = 1; memset(head, -1, sizeof(head)); } void addedge(int u, int v){ node[cnt].v = v; node[cnt].vis = 0; node[cnt].next = head[u]; head[u] = cnt++; } void DFS(int u){ for(int i = head[u]; i!=-1; i=node[i].next){ if(!node[i].vis){ node[i].vis = true; DFS(node[i].v); cout << u << endl; } } } int main(){ scanf("%d%d",&n,&m); Init(); int u,v; for(int i=0; i<m; i++){ scanf("%d%d",&u,&v); addedge(u, v); addedge(v, u); } cout << "1" << endl; DFS(1); return 0; }
相关文章推荐
- POJ 2230 Watchcow && USACO Watchcow 2005 January Silver (欧拉回路)
- Poj 2230 Watchcow【欧拉回路】
- POJ2230 Watchcow【欧拉回路】
- POJ2230 Watchcow——欧拉回路
- POJ2230 Watchcow【欧拉回路】
- POJ 2230 Watchcow
- poj 2230——Watchcow
- POJ 2230 Watchcow(欧拉图)
- poj - 2230 - Watchcow(欧拉回路)
- poj 2230 Watchcow 有向欧拉图
- POJ2230 Watchcow(欧拉回路)
- poj 2230 Watchcow 欧拉回路
- POJ 2230 Watchcow(欧拉回路:输出点轨迹)
- POJ - 2230 Watchcow
- (POj 2230)Watchcow [有向欧拉图] 输出欧拉回路
- poj 2230 Watchcow(欧拉回路)
- poj——2230——Watchcow(欧拉路+dfs)
- poj 2230 Watchcow
- POJ 2230 Watchcow 欧拉路径 DFS
- POJ2230 Watchcow 【欧拉回路】+【DFS】