题目链接: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(欧拉回路:输出点路径)的更多相关文章

  1. POJ 2230 Watchcow 欧拉回路的DFS解法(模板题)

    Watchcow Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 9974 Accepted: 4307 Special Judg ...

  2. [欧拉] poj 2230 Watchcow

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

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

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

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

  5. POJ 2230 Watchcow (欧拉回路)

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

  6. poj 2230 Watchcow(欧拉回路)

    关键是每条边必须走两遍,重复建边即可,因为确定了必然存在 Euler Circuit ,所以所有判断条件都不需要了. 注意:我是2500ms跑过的,鉴于这道题ac的code奇短,速度奇快,考虑解法应该 ...

  7. POJ 2230 Watchcow

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

  8. POJ 2230 Watchcow 【欧拉路】

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

  9. POJ 2230 Watchcow 欧拉图

    Watchcow Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 8800   Accepted: 3832   Specia ...

随机推荐

  1. loj2541 「PKUWC2018」猎人杀 【容斥 + 分治NTT】

    题目链接 loj2541 题解 思路很妙啊, 人傻想不到啊 觉得十分难求,考虑容斥 由于\(1\)号可能不是最后一个被杀的,我们容斥一下\(1\)号之后至少有几个没被杀 我们令\(A = \sum\l ...

  2. 【learning】加权拟阵与贪心

    首先.. 这篇东西的话算是一个关于拟阵部分知识的小总结,有些语言相对来说偏向便于理解方面,所以可能..有一些说法会不是那么严谨大概是这样 ​ 一些概念 线性无关:一组数据中没有一个量可以写成其余量的线 ...

  3. selenium - 查看selenium版本信息

    1. pip list 2. pip show selenium 3. cmd>>python >>> import selenium>>> help( ...

  4. Codeforces 892 C.Pride

    C. Pride time limit per test 2 seconds memory limit per test 256 megabytes input standard input outp ...

  5. python学习笔记(七) 类和pygame实现打飞机游戏

    python中类声明如下: class Student(object): def __init__(self, name, score): self.name = name self.score = ...

  6. HashMap源码翻译

    /* * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. * ORACLE PROPRIETA ...

  7. HDU 4496 并查集 逆向思维

    给你n个点m条边,保证已经是个连通图,问每次按顺序去掉给定的一条边,当前的连通块数量. 与其正过来思考当前这边会不会是桥,不如倒过来在n个点即n个连通块下建图,检查其连通性,就能知道个数了 /** @ ...

  8. 你知道吗?31种 CSS 选择器的应用

    选择器(selector)是CSS中很重要的概念,所有HTML语言中的标记都是通过不同的CSS选择器进行控制的.用户只需要通过选择器对不同的HTML标签进行控制,并赋予各种样式声明,即可实现各种效果. ...

  9. HTML DOM 节点介绍(nodeName,nodeValue,nodeType)

    对于初学者来说,HTML DOM 里面的 nodeName.nodeValue 以及 nodeType 三个属性的作用和取值不是很清楚.下面整理的信息包含有关于节点的详细信息,供参考. 节点信息 每个 ...

  10. 【CodeForces】899 E. Segments Removal

    [题目]E. Segments Removal [题意]给定n个数字,每次操作删除最长的连续相同数字(等长删最左),求全部删完的最少次数.n<=2*10^6,1<=ai<=10^9. ...