POJ 2230 Watchcow(欧拉回路:输出点路径)
题目链接:http://poj.org/problem?id=2230
题目大意:给你n个点m条边,Bessie希望能走过每条边两次,且两次的方向相反,让你输出以点的形式输出路径。
解题思路:其实就是输出有向图的欧拉路,只是让你以点的形式输出。建图的时候,输入a,b直接建立(a,b)和(b,a)正反两条边,然后dfs递归遍历即可。注意输出点的位置:在边遍历完之后输出,原理暂时还没搞懂。
代码:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<stack>
#define CLR(arr,val) memset(arr,val,sizeof(arr))
using namespace std;
const int N=1e5+;
const int M=1e5+;
const int INF=0x3f3f3f3f; struct node{
int to,next;
}edge[M]; int idx;;
int head[N];
bool vis[N]; void init(){
idx=;
CLR(head,);
CLR(vis,false);
} void addedge(int u,int v){
edge[idx].to=v;
edge[idx].next=head[u];
head[u]=idx++;
} void dfs(int u){
for(int &j=head[u];j;j=edge[j].next){
node t=edge[j];
if(!vis[j]){
vis[j]=true;
dfs(t.to);
//不知道这样为什么错。。。先记着吧
//printf("%d\n",t.to);
}
}
printf("%d\n",u);
} int main(){
init();
int n,m;
scanf("%d%d",&n,&m);
for(int i=;i<=m;i++){
int a,b;
scanf("%d%d",&a,&b);
addedge(a,b);
addedge(b,a);
}
dfs();
return ;
}
POJ 2230 Watchcow(欧拉回路:输出点路径)的更多相关文章
- POJ 2230 Watchcow 欧拉回路的DFS解法(模板题)
Watchcow Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 9974 Accepted: 4307 Special Judg ...
- [欧拉] poj 2230 Watchcow
主题链接: http://poj.org/problem? id=2230 Watchcow Time Limit: 3000MS Memory Limit: 65536K Total Submi ...
- 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 && 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: 5258 Accepted: 2206 Specia ...
- poj 2230 Watchcow(欧拉回路)
关键是每条边必须走两遍,重复建边即可,因为确定了必然存在 Euler Circuit ,所以所有判断条件都不需要了. 注意:我是2500ms跑过的,鉴于这道题ac的code奇短,速度奇快,考虑解法应该 ...
- POJ 2230 Watchcow
Watchcow Time Limit: 3000ms Memory Limit: 65536KB This problem will be judged on PKU. Original ID: 2 ...
- 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 ...
随机推荐
- BZOJ1187:[HNOI2007]神奇游乐园——题解
http://www.lydsy.com/JudgeOnline/problem.php?id=1187 Description 经历了一段艰辛的旅程后,主人公小P乘坐飞艇返回.在返回的途中,小P发现 ...
- max os取消开机启动
原文:http://liuzhichao.com/p/1667.html 安装MAMP后,启动服务时提示Apache启动失败,80端口被占用.查看进程发现存在几个httpd. OS X自带Apache ...
- 电子商务(电销)平台中商品模块(Product)数据库设计明细
以下是自己在电子商务系统设计中的数据库设计经验总结,而今发表出来一起分享,如有不当,欢迎跟帖讨论~ 商品表 (product)|-- 自动编号 (product_id)|-- 商品名称 (produc ...
- Codeforces Round #358 (Div. 2) A B C 水 水 dfs序+dp
A. Alyona and Numbers time limit per test 1 second memory limit per test 256 megabytes input standar ...
- [CQOI2009] 中位数 (前缀和)
[CQOI2009] 中位数 题目描述 给出1~n的一个排列,统计该排列有多少个长度为奇数的连续子序列的中位数是b.中位数是指把所有元素从小到大排列后,位于中间的数. 输入输出格式 输入格式: 第一行 ...
- lnmp集成环境Access Denied的问题
在你的php.ini配置文件中,设置cgi.fix_pathinfo=1
- STL源码分析-deque
http://note.youdao.com/noteshare?id=66f21dca07c1984f41848700021644fd
- Nginx多个配置文件共用location配置
一.应用情况 很多时候我们在一台服务器上部署了不止 一个项目,我们通过Nginx来代理,为了方便管理往往会将各个项目的配置分开写到不同的配置文件中,如: 在nginx.conf 文件中加上 incl ...
- libcurl移植到android
一.总体概览 C库:libcurl 3.7 目标平台:android 编译平台:ubuntu 12 编译工具:ndk r7 or later 二.已知方法 1. 官网上给了两种方法,第一种方法是使用a ...
- dp ZOJ 3956
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3956 Course Selection System Time Limit ...