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奇短,速度奇快,考虑解法应该 ...
随机推荐
- JavaScript实验一(添加节点,删除节点)
静态html页面: <!DOCTYPE html> <html> <head lang="en"> <meta charset=" ...
- GROUP BY 和 ORDER BY 的一起使用
GROUP BY 和 ORDER BY一起使用 写程序也有很长的一段时间了,有些东西我总不曾去思考,很少去积累一些有用的东西,总喜欢"用要即拿"的心态来对待,这是非常不好的坏习惯. ...
- 01springMVC入门
1 MVC模式回顾 Spring MVC是一种基于MVC的Web应用框架. MVC是一种设计模式,MVC在b/s系统下的应用: 执行步骤: 发出请求,请求到MVC当中的C,C接收请求后并不能 ...
- telnet允许root用户登录
默认情况下,linux不允许root用户以telnet方式登录linux主机,若要允许root用户登录,可采取以下3种方法之一: 1.修改login文件 redhat中对于远程登录的限制体现在/ ...
- Oracle-查看用户对象信息
--视图(可查看拥有者.对象名称.创建时间.上次修改时间) SELECT t.OBJECT_NAME, t.CREATED, t.LAST_DDL_TIME FROM user_objects t o ...
- C++里面mutable的作用
mutalbe的中文意思是“可变的,易变的”,跟constant(既C++中的const)是反义词. 在C++中,mutable也是为了突破const的限制而设置的.被mutable修饰的变量,将永远 ...
- Codeforces Round #316 (Div. 2)E. Pig and Palindromes DP
E. Pig and Palindromes Peppa the Pig was walking and walked into the forest. What a strange coinci ...
- vmvare如何安装xp虚拟机
http://jingyan.baidu.com/article/a681b0ded8e25e3b19434640.html 一直以来,许多的朋友都不熟悉怎么安装在虚拟机上装windows系统 200 ...
- 36.QT地图
widget.h #ifndef MAPWIDGET_H #define MAPWIDGET_H #include <QGraphicsView> #include <QLabel& ...
- 6 ZigZig Conversion[M]Z字形变换
题目 The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows li ...