POJ 2230 Watchcow 欧拉图
Time Limit: 3000MS | Memory Limit: 65536K | |||
Total Submissions: 8800 | Accepted: 3832 | Special Judge |
Description
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<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<string>
#include<cmath>
#include<map>
#define debug(a) cout << #a << " " << a << endl
using namespace std;
typedef long long ll;
const int MAXN = ; //数组得开到两倍,因为这里做处理变成有向图扩大了两倍
struct node {
int to, next;
};
node edge[MAXN];
int head[MAXN], vis[MAXN], n, m, ans;
void dfs( int x ) {
for( int i = head[x]; i != -; i = edge[i].next ) {
if( !vis[i] ) {
vis[i] = ;
dfs(edge[i].to);
}
}
cout << x << endl;
}
int main() {
while( cin >> n >> m ) {
for( int i = ; i < MAXN; i ++ ) {
head[i] = -;
}
ans = ;
memset( vis, , sizeof(vis) );
while( m -- ) {
int x, y;
cin >> x >> y;
edge[ans].to = y;
edge[ans].next = head[x];
head[x] = ans;
ans ++;
edge[ans].to = x;
edge[ans].next = head[y];
head[y] = ans;
ans ++;
}
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
Watchcow Time Limit: 3000ms Memory Limit: 65536KB This problem will be judged on PKU. Original ID: 2 ...
- 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 欧拉回路的DFS解法(模板题)
Watchcow Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 9974 Accepted: 4307 Special Judg ...
- poj 2230 Watchcow(欧拉回路)
关键是每条边必须走两遍,重复建边即可,因为确定了必然存在 Euler Circuit ,所以所有判断条件都不需要了. 注意:我是2500ms跑过的,鉴于这道题ac的code奇短,速度奇快,考虑解法应该 ...
随机推荐
- Java匹马行天下之J2EE框架开发——Spring—>Spring框架知多少
————也许我注定成不了一个伟大的人,但是至少我可以做一个很棒的自己.我想我现在应该做的不是瞻前顾后,而是活在当下,正确认知自己,做好自己现在的工作,努力提升自己的能力,踏踏实实地做一个程序员 一.思 ...
- DesignPattern系列__10单例模式
单例模式介绍 单例模式,是为了确保在整个软件体统中,某个类对象只有一个实例,并且该类通常会提供一个对外获取该实例的public方法(静态方法). 比如日志.数据库连接池等对象,通常需要且只需要一个实例 ...
- Centos安装git并配置ssh
1.下载git安装包 git-2.9.4.tar.gz 2.解压 tar -xzvf git-2.9.4.tar.gz 3.修改解压后的文件名 mv git-2.9.4 git 4.安装git依赖的库 ...
- Scala类和对象(二)
1. 类和属性 1.1 如何控制构造函数字段的可见性 在Scala中: 如果一个字段被声明为var, Scala会为该字段生成getter和setter方法. 如果字段是val, Scala只生成ge ...
- JavaWeb配置详解(结合框架SpringMVC)
详解 先说一说常识性的东西,我们的JavaWeb程序运行一开始走的是web.xml文件,这是我们的核心文件,可以说没有web.xml文件我们就无法运行项目,这个文件长什么样子,读者自己新建一个web项 ...
- azure k8s netcore 程序初次部署
以下都是我在2018年12月份做的实验,今天才发布出来. 念想 首先是了解一些关于K8s的一些基础概念,推荐查看一下这个链接,非常适合入门k8s.是因为K8S的环境搭建比较复杂(最主要是懒),其实也有 ...
- Java连载16-++传参&关系运算符
一.++再举例 int a = 10; System.out.print(a++);//这里会打印出10,因为他们内部这个print函数有参数相当于参数x=a++ System.out.println ...
- 基于jmeter+perfmon的稳定性测试记录
1. 引子 最近承接了项目中一些性能测试的任务,因此决定记录一下,将测试的过程和一些心得收录下来. 说起来性能测试算是软件测试行业内,有些特殊的部分.这部分的测试活动,与传统的测试任务差别是比较大的, ...
- Python 数据科学-Numpy
NumPy Numpy :提供了一个在Python中做科学计算的基础库,重在数值计算,主要用于多维数组(矩阵)处理的库.用来存储和处理大型矩阵,比Python自身的嵌套列表结构要高效的多.本身是由C语 ...
- 结合suctf-upload labs-RougeMysql再学习
这篇主要记录一下这道题目的预期解法 做这道题首先要在自己的vps搭建一个rouge mysql,里面要填写需要读取客户端的文件名,即我们上传的phar文件路径 先搭一个rouge mysql测试看看: ...