Watchcow

Time Limit: 3000ms
Memory Limit: 65536KB

This problem will be judged on PKU. Original ID: 2230
64-bit integer IO format: %lld      Java class name: Main

 
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.

 

Input

* Line 1: Two integers, N and M.

* 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...

 

Source

 
解题:欧拉回路
 
 #include <cstdio>
#include <cstring>
using namespace std;
const int maxn = ;
struct arc {
int to,next;
arc(int x = ,int y = -) {
to = x;
next = y;
}
} e[];
int head[maxn],tot,n,m;
bool vis[];
void add(int u,int v) {
e[tot] = arc(v,head[u]);
head[u] = tot++;
}
void dfs(int u) {
for(int &i = head[u]; ~i; i = e[i].next) {
if(vis[i]) continue;
vis[i] = true;
dfs(e[i].to);
}
printf("%d\n",u);
}
int main() {
int u,v;
while(~scanf("%d%d",&n,&m)) {
memset(head,-,sizeof head);
memset(vis,false,sizeof vis);
for(int i = tot = ; i < m; ++i) {
scanf("%d%d",&u,&v);
add(u,v);
add(v,u);
}
dfs();
}
return ;
}

POJ 2230 Watchcow的更多相关文章

  1. [欧拉] poj 2230 Watchcow

    主题链接: http://poj.org/problem? id=2230 Watchcow Time Limit: 3000MS   Memory Limit: 65536K Total Submi ...

  2. POJ 2230 Watchcow(欧拉回路:输出点路径)

    题目链接:http://poj.org/problem?id=2230 题目大意:给你n个点m条边,Bessie希望能走过每条边两次,且两次的方向相反,让你输出以点的形式输出路径. 解题思路:其实就是 ...

  3. POJ 2230 Watchcow(有向图欧拉回路)

    Bessie's been appointed the new watch-cow for the farm. Every night, it's her job to walk across the ...

  4. POJ 2230 Watchcow (欧拉回路)

    Watchcow Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 5258   Accepted: 2206   Specia ...

  5. POJ 2230 Watchcow && USACO Watchcow 2005 January Silver (欧拉回路)

    Description Bessie's been appointed the new watch-cow for the farm. Every night, it's her job to wal ...

  6. POJ 2230 Watchcow 【欧拉路】

    Watchcow Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 6336   Accepted: 2743   Specia ...

  7. POJ 2230 Watchcow 欧拉图

    Watchcow Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 8800   Accepted: 3832   Specia ...

  8. POJ 2230 Watchcow 欧拉回路的DFS解法(模板题)

    Watchcow Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 9974 Accepted: 4307 Special Judg ...

  9. poj 2230 Watchcow(欧拉回路)

    关键是每条边必须走两遍,重复建边即可,因为确定了必然存在 Euler Circuit ,所以所有判断条件都不需要了. 注意:我是2500ms跑过的,鉴于这道题ac的code奇短,速度奇快,考虑解法应该 ...

随机推荐

  1. BA-防冻开关的安装

    防冻开关学名:防冻恒温保护器,在通风空调系统中监测加热盘管空气侧温度来防止盘管冻坏.具有较小的转换差和良好的重复性.可自动复位.当在30cm长的毛细管上温度低于选择的设定值时会产生一个闭合信号给DDC ...

  2. BA-siemens-ppm模块在ALN层通信

    PPM作为新的扩展模块,有MS/TP通讯的能力,但是在常规设置的时候必须设置在PXC Modular下面,PPM上线也必须在PXC Modular上中超级终端设置,偶然通过一个项目实现了PPM挂载在A ...

  3. 6 Javascript:函数

    函数 函数是面向任务的. 当我们面临一个须要可问题的时候.往往无处下手.这时候.须要将问题分解为多个任务,从而逐一击破. 这里就须要函数的帮助. 语法 function Name() { Body() ...

  4. clipper库使用的一些心得

    clipper sourceforge官网:http://sourceforge.net/projects/polyclipping/ 1. 版本号差异 之前project里面使用4.8.6,近期升级 ...

  5. ANT公布SVN WEB项目到TOMCAT以及利用post-commit自己主动提交编译更新

    开发者在本地提交更新到SVNserver后.往往须要測试人员又一次測试.为了将更新内容即时反映到測试server.能够利用post-commit脚本将SVN更新同步到測试server中. (1)利用S ...

  6. Android 利用TimerTask实现ImageView图片播放效果

    在项目开发中,往往 要用到图片播放的效果.今天就用TimerTask和ImageView是实现简单的图片播放效果. 当中,TimerTask和Timer结合一起使用.主要是利用TimerTask的迭代 ...

  7. 14. Longest Common Prefix[E]最长公共前缀

    题目 Write a function to find the longest common prefix string amongst an array of strings. If there i ...

  8. Hessian实例

    简述Hessian Hessian是一个由Caucho Technology开发的轻量级RPC框架,由于它使用二进制RPC协议,所以它更快.更简单,很适合于发送二进制数据(访问官网): 在进行基于He ...

  9. CodeIgniter 相关资源

    CodeIgniter ci 如果需要扩展多个base Controller,譬如一个 core/MY_Controller表示基本Controller,一个  core/MY_AuthControl ...

  10. Arduino扫盲(持续添加中)

    1.Arduino火的很,很大一点在于,他基本透明掉了硬件电子部分,只剩下软件部分,通过把电子部分包装成黑箱,使得大量IT人士,普通人,甚至小学生也能玩的来. 2 .Arduino是一个电子原型开发平 ...