[2016-01-27][POJ][2230][Watchcow]
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[2016-01-27][POJ][2230][Watchcow]相关的知识,希望对你有一定的参考价值。
[2016-01-27][POJ][2230][Watchcow]Description
Bessie‘s been appointed the new watch-cow for the farm. Every night, it‘s her job to walk across the farm and make sure that no evildoers are doing any evil. She begins at the barn, makes her patrol, and then returns to the barn when she‘s done.
If she were a more observant cow, she might be able to just walk each of M (1 <= M <= 50,000) bidirectional trails numbered 1..M between N (2 <= N <= 10,000) fields numbered 1..N on the farm once and be confident that she‘s seen everything she needs to see. But since she isn‘t, she wants to make sure she walks down each trail exactly twice. It‘s also important that her two trips along each trail be in opposite directions, so that she doesn‘t miss the same thing twice.
A pair of fields might be connected by more than one trail. Find a path that Bessie can follow which will meet her requirements. Such a path is guaranteed to exist.
If she were a more observant cow, she might be able to just walk each of M (1 <= M <= 50,000) bidirectional trails numbered 1..M between N (2 <= N <= 10,000) fields numbered 1..N on the farm once and be confident that she‘s seen everything she needs to see. But since she isn‘t, she wants to make sure she walks down each trail exactly twice. It‘s also important that her two trips along each trail be in opposite directions, so that she doesn‘t miss the same thing twice.
A pair of fields might be connected by more than one trail. Find a path that Bessie can follow which will meet her requirements. Such a path is guaranteed to exist.
Input
* Line 1: Two integers, N and M.
* Lines 2..M+1: Two integers denoting a pair of fields connected by a path.
* Lines 2..M+1: Two integers denoting a pair of fields connected by a path.
Output
* Lines 1..2M+1: A list of fields she passes through, one per line, beginning and ending with the barn at field 1. If more than one solution is possible, output any solution.
Sample Input
4 5 1 2 1 4 2 3 2 4 3 4
Sample Output
1 2 3 4 2 1 4 3 2 4 1
Hint
OUTPUT DETAILS:
Bessie starts at 1 (barn), goes to 2, then 3, etc...
Bessie starts at 1 (barn), goes to 2, then 3, etc...
- 时间:2016-01-26 21:58:37 星期二
- 题目编号:POJ 2230 watchcow
- 题目大意:给出n个顶点,n条边,以1为起点,输出 经过每条边两次(每次方向相反),的路径
- 分析:
- 无向边 相当于 两个方向方向相反的有向边
- 方法:
- DFS,从1开始dfs,遍历每一个顶点,每走过一条边,打上标记,直到无路可走
- 解题过程遇到问题:
- 题目是无向边,最大边数是 2*maxm
- 邻接表的数组实现.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 [2016-01-27][POJ][1751][B - Highways]
|