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 ...
随机推荐
- sysbench - 单组件式测试工具
1 安装 > ./configure --with-mysql-includes=/usr/local/mysql/include --with-mysql-libs=/usr/local/my ...
- 【神仙题】【CF28D】 Don't fear, DravDe is kind
传送门 Description 一个有N辆卡车的车队从城市Z驶向城市3,来到了一条叫做"恐惧隧道"的隧道.在卡车司机中,有传言说怪物DravDe在那条隧道里搜寻司机.有些司机害怕先 ...
- 《JavaScript高级程序设计(第三版)》-2
变量 ECMAScript变量是松散类型的,即可以保存任何类型的数据. 初始化变量不会把它标记类型,初始化的过程只是给变量付一个值,因此可以在修改变量的同时修改值的类型.但并不推荐这样做. var m ...
- Codeforces 97.B Superset
A set of points on a plane is called good, if for any two points at least one of the three condition ...
- Ubuntu配置vncserver
https://help.aliyun.com/knowledge_detail/59330.html 首先,安装桌面环境和vnc4server: sudo apt-get install gnome ...
- js 多个事件的绑定及移除(包括原生写法和 jquery 写法)
需要打开控制台查看效果: <!DOCTYPE html> <html lang="en"> <head> <meta charset=&q ...
- 5.UiScrollable API 详细介绍
Tip: 1.扫动过程中如果界面停留在滚动条的中间部分会先回到起点再进行滚动 2.扫动过程中设置的步长长短决定划过内容的多少,步长越长滑过的内容就越少:步长越短划过的内容就越长 一.UiScrolla ...
- OpenCV---像素运算
像素运算 分为算术运算和逻辑运算 算术运算: 加减乘除 调节亮度 调整对比度 逻辑运算: 与或非 遮罩层控制 一:算术运算 import cv2 as cv import numpy as np de ...
- Oracle用imp导入dmp文件记录一下
---------------------------------------------------------------------------------------------------- ...
- cmd下常用命令汇总
1.获得文件夹内所有文件的文件名列表 dir *.png /b>list.txt 其中: (1)*.png表示筛选后缀为.png的文件 (2)/b为输出的模式.如下: 引用 /b 只有文件名 ...