POJ 2230 Watchcow
Watchcow
This problem will be judged on PKU. Original ID: 2230
64-bit integer IO format: %lld Java class name: Main
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
* Lines 2..M+1: Two integers denoting a pair of fields connected by a path.
Output
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
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的更多相关文章
- [欧拉] poj 2230 Watchcow
主题链接: http://poj.org/problem? id=2230 Watchcow Time Limit: 3000MS Memory Limit: 65536K Total Submi ...
- POJ 2230 Watchcow(欧拉回路:输出点路径)
题目链接:http://poj.org/problem?id=2230 题目大意:给你n个点m条边,Bessie希望能走过每条边两次,且两次的方向相反,让你输出以点的形式输出路径. 解题思路:其实就是 ...
- POJ 2230 Watchcow(有向图欧拉回路)
Bessie's been appointed the new watch-cow for the farm. Every night, it's her job to walk across the ...
- POJ 2230 Watchcow (欧拉回路)
Watchcow Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 5258 Accepted: 2206 Specia ...
- 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 ...
- POJ 2230 Watchcow 【欧拉路】
Watchcow Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 6336 Accepted: 2743 Specia ...
- POJ 2230 Watchcow 欧拉图
Watchcow Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 8800 Accepted: 3832 Specia ...
- POJ 2230 Watchcow 欧拉回路的DFS解法(模板题)
Watchcow Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 9974 Accepted: 4307 Special Judg ...
- poj 2230 Watchcow(欧拉回路)
关键是每条边必须走两遍,重复建边即可,因为确定了必然存在 Euler Circuit ,所以所有判断条件都不需要了. 注意:我是2500ms跑过的,鉴于这道题ac的code奇短,速度奇快,考虑解法应该 ...
随机推荐
- poj 1611 简单并查集的应用
#include<stdio.h> #define N 31000 int pre[N]; int find(int x) { if(x!=pre[x]) pre[x]=find( ...
- Gradle的奇妙之处
转载请注明出处:http://blog.csdn.net/crazy1235/article/details/50465885 Google I/O 2013大会上公布了AS,现在已经发展到2.0-b ...
- android一个弹出菜单的动画(一)
先上效果图: 先写Layout文件: <?xml version="1.0" encoding="utf-8"? > <RelativeLay ...
- 局域网网络性能測试方法HDtune 64K有缓存測速法,让你得知你的网络性能
该方法能够有效測试出您的网络传输性能究竟有多高,该方法通用于有盘,无盘(系统虚拟盘) ,游戏虚拟盘,以及其它带有缓存功能的虚拟盘软件,可是由于每款软件的工作方式和原理都不仅同样,所以每款软件的測试结果 ...
- idea 中web项目 用自带tomcat启动问题,
严重: Exception sending context initialized event to listener instance of class com.zenointel.logserve ...
- 编译最新版webrtc源码和编译好的整个项目10多个G【分享】
编译最新版webrtc源码和编译好的整个项目10多个G[分享] 参考https://webrtc.org/native-code/development/编译最新版webrtc源码: Git clon ...
- block的一些注意事项
1,定义block时是可以同时进行赋值的 2,block中是代码块,就是里面写的是语句,需要加分号 3,在block中,允许有多条语句 4,在带有参数的block中,声明部分参数名可以省略,但是建议写
- dubbo 解决既是消费者又是提供者 Duplicate application configs 的问题
首先 有应用A 是 提供者 应用B 来实现既是消费者又是提供者 在应用 B 这边新建两个xml dubbo-consumer.xml 消费者 <!-- 自动扫描注解:通过dubbo实现 - ...
- 主流的Python领域和框架--转
原文地址:https://www.zhihu.com/question/19899608
- 了解和解决SQL SERVER阻塞问题(copy)
http://support.microsoft.com/kb/224453 Summary In this article, the term "connection" refe ...