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 设计模式 – Observer 观察者模式
目录 [隐藏] 1 代码 1.1 观察者接口: 1.2 被观察者: 1.3 观众类 : 1.4 电影类: 1.5 效果如下: 代码 说明都在注释: 观察者接口: package ObserverMod ...
- 33行代码爬取妹子图片(bs4+urllib)
from bs4 import BeautifulSoupimport urllib2import urllibimport lxmlimport os def get_imgs(): image_c ...
- laravel新项目报错 No application encryption key has been specified.
解决办法, 若文件根目录下没有 .env 1..env.example 改名使用命令 copy 修改为 .env 2.使用命令 php artisan key:generate 获取密码,自动保存到 ...
- Flutter学习笔记(16)--Scaffold脚手架、AppBar组件、BottomNavigationBar组件
如需转载,请注明出处:Flutter学习笔记(15)--MaterialApp应用组件及routes路由详解 今天的内容是Scaffold脚手架.AppBar组件.BottomNavigationBa ...
- lnmp环境搭建方法
网上目前的一键搭建方法: 命令行安装: 1.源码编译安装:(个性化配置,安装配置过程繁琐) 2.使用yum或apt直接安装:(使用编译好的二进制文件安装,速度快) 3.军哥的lnmp一键脚本安装: 4 ...
- Go-json解码到结构体-踩坑
package main import ( "encoding/json" "fmt" ) type User struct { Name string `js ...
- 「雕爷学编程」Arduino动手做(15)——手指侦测心跳模块
37款传感器和模块的提法,在网络上广泛流传,其实Arduino能够兼容的传感器模块肯定是不止37种的.鉴于本人手头积累了一些传感器与模块,依照实践出真知(动手试试)的理念,以学习和交流为目的,这里准备 ...
- Zabbix-设置自动发现规则实例
一.前文 此篇文章,主要针对自动发现规则中使用snmpv2类型发现 zabbix官方解读,可当参考: https://www.zabbix.com/documentation/4.0/zh/man ...
- JavaScript中一个方法同时发送两个ajax请求问题
今天在做项目中遇到一个问题,大概是在一个jsp页面同时有一个select下拉搜索条件框和一个Bootstrap表格展示列表.这两个都要通过ajax向后台拿数据,而且要在页面加载时完成.当时的做法是: ...
- Docker跨服务器通信Overlay解决方案(下) Consul集群
承接上文 本文基于上篇文章,详细的场景说明与分析在前篇随笔中业已记录,有兴趣可以移步 Docker跨服务器通信Overlay解决方案(上) Consul单实例 本文主旨 本文为Docker使用Cons ...