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

 
思路:打印欧拉通路,题目保证有解,直接DFS打印即可,代码如下:
const int maxm = ;
const int maxn = ; struct Node {
int from, to;
Node(int _from, int _to) : from(_from), to(_to){}
}; int N, M, vis[maxn*];
vector<int> ans, G[maxm];
vector<Node> edges; void addedge(int u,int v) {
edges.push_back(Node(u, v));
G[u].push_back(edges.size() - );
} void dfs(int x) {
int len = G[x].size();
for(int i = ; i < len; ++i) {
if(!vis[G[x][i]]) {
vis[G[x][i]] = ;
dfs(edges[G[x][i]].to);
ans.push_back(edges[G[x][i]].to);
}
}
} int main() {
scanf("%d%d", &N, &M);
for (int i = ; i < M; ++i) {
int t1, t2;
scanf("%d%d", &t1, &t2);
addedge(t1, t2);
addedge(t2, t1);
}
dfs();
int len = ans.size();
for(int i = ; i < len; ++i)
printf("%d\n", ans[i]);
printf("1\n");
return ;
}

Day4 - D - Watchcow POJ - 2230的更多相关文章

  1. 欧拉回路输出(DFS,不用回溯!)Watchcow POJ 2230

    Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 8109   Accepted: 3551   Special Judge D ...

  2. [欧拉] poj 2230 Watchcow

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

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

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

  4. 【POJ 2230】 Watchcow

    [题目链接] http://poj.org/problem?id=2230 [算法] 欧拉回路 [代码] #include <algorithm> #include <bitset& ...

  5. POJ 2230 Watchcow

    Watchcow Time Limit: 3000ms Memory Limit: 65536KB This problem will be judged on PKU. Original ID: 2 ...

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

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

  7. POJ 2230 Watchcow (欧拉回路)

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

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

  9. POJ 2230 Watchcow 【欧拉路】

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

随机推荐

  1. 【CoreBluetooth】iOS 系统蓝牙框架

    https://www.jianshu.com/p/eb58dcbae5f9 2016.06.07 23:04* 字数 285 阅读 852评论 4喜欢 3 暂时 第一次功能性研究,具体实现,后续添加 ...

  2. New Airless Pump Bottle Technical Features

    Airless Pump Bottle    protect sensitive products such as natural skin creams, serums, foundations a ...

  3. IDEA快捷键/本文仅供自己参考使用如有侵权立删

    好好来学习学习IDEA这款神器,让你的效率飞起!视频来自慕课网 本文转载 更多技巧 代码定位 跳转: 1.IDEA的左侧侧边栏有1:Project.7:Structure和2:Favorities a ...

  4. HDU1176免费馅饼(DP)

    都说天上不会掉馅饼,但有一天gameboy正走在回家的小径上,忽然天上掉下大把大把的馅饼.说来gameboy的人品实在是太好了,这馅饼别处都不掉,就掉落在他身旁的10米范围内.馅饼如果掉在了地上当然就 ...

  5. 1014 Waiting in Line (30分)

    1014 Waiting in Line (30分)   Suppose a bank has N windows open for service. There is a yellow line i ...

  6. java 8时间使用LocalDateTime,ZonedDateTime,LocalDate

    前言 java 8的时间已经能够满足日常的使用,也方便理解.joda-time作为一个有优秀的时间组件也不得不告知使用者在java 8以后使用自带的时间 LocalDateTime以及ZonedDat ...

  7. go笔记(go中的方法调用)

    最近接触go语言  发现和java的方法调用有些类似但又有自己的注意点 go的包我理解为则是隔离的最小模块 先在src目录下创建main.go文件  package为main,然后在src下创建mod ...

  8. .Net后台实现支付宝APP支付

    前面讨论了微信支付,接下来聊聊支付宝的APP支付(新款支付宝支付).其实这些支付原理都一样,只不过具体到每个支付平台,所使用的支付配置参数不同,返回至支付端的下单参数也不同. 话不多说,直接上代码. ...

  9. iOS沙盒目录简介、沙盒路径获取

    一.沙盒的意义 出于安全的考虑,iOS系统的沙盒机制规定每个应用只能访问当前沙盒目录下面的文件.但是对于一些用户级别的数据,考虑到很多软件都需要使用其中的数据,用户可以通过对当前的软件授权,让当前的应 ...

  10. 题解 AT1219 【歴史の研究】

    莫队 简单分析:题面含有IOI(惊),可知此题是IOI(数字三角形)难度(逃). 思路:回滚莫队 当然很多人都是抱着学回滚莫队的目标来看这道题的,所以这里介绍一下回滚莫队. 1.按莫队的思路讲询问排序 ...