关键是每条边必须走两遍,重复建边即可,因为确定了必然存在 Euler Circuit ,所以所有判断条件都不需要了。

注意:我是2500ms跑过的,鉴于这道题ac的code奇短,速度奇快,考虑解法应该不唯一。

 #include<cstdio>
#include<cstring>
#include<vector>
#include<stack>
#include<algorithm>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define clr(a,m) memset(a,m,sizeof(a))
using namespace std; const int MAXN=;
const int MAXM=; struct Edge{
int v,next,vis;
Edge(){}
Edge(int _v,int _next):v(_v),next(_next),vis(){}
}edge[MAXM<<]; stack<int>stk;
int head[MAXN],tol;
int degree[MAXN]; void init()
{
tol=;
clr(head,-);
} void add(int u,int v)
{
edge[tol]=Edge(v,head[u]);
head[u]=tol++; edge[tol]=Edge(u,head[v]);
head[v]=tol++;
} void FindEuler(int u)
{
for(int i=head[u];i!=-;i=edge[i].next)
{
int v=edge[i].v; if(!edge[i].vis){
edge[i].vis=edge[i^].vis=;
FindEuler(v);
stk.push(v);
}
}
} void EulerCircuit(int n)
{
while(!stk.empty())
stk.pop();
FindEuler();
} int main()
{
int n,m,x,y;
scanf("%d%d",&n,&m); init();
clr(degree,);
rep(i,,m-){
scanf("%d%d",&x,&y);
x--;y--;
add(x,y);
add(x,y);
degree[x]+=;
degree[y]+=;
} EulerCircuit(n);
stk.push();
while(!stk.empty())
{
x=stk.top();stk.pop();
printf("%d\n",x+);
}
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(欧拉回路:输出点路径)

    题目链接:http://poj.org/problem?id=2230 题目大意:给你n个点m条边,Bessie希望能走过每条边两次,且两次的方向相反,让你输出以点的形式输出路径. 解题思路:其实就是 ...

  6. POJ 2230 Watchcow (欧拉回路)

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

  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. 【转载】Hadoop历史服务器详解

    免责声明:     本文转自网络文章,转载此文章仅为个人收藏,分享知识,如有侵权,请联系博主进行删除.     原文作者:过往记忆(http://www.iteblog.com/)     原文地址: ...

  2. switch..case函数的基础使用一

    基本作用:switch中的参数与case的值进行比对,相等则进入case. JDK1.7 switch支持int.Integer.String类型 package com.my.test; impor ...

  3. 基于AgileEAS.NET企业应用开发平台的分布式解决方案

    开篇 分布式应用 AgileEAS.NET基于Microsoft .Net构件技术而构建,Microsoft .Net最吸引人的莫过于分布式应用技术,基已经提供了XML WebService. .Ne ...

  4. Java---算法---插入排序

    /** * 插入排序(升序) * * @param array */ public static void insertSort(int[] array) { int j = 0; // 下标从1开始 ...

  5. action间传多个参数时注意问题

    通常我们action之间传参可以有多种形式,举例说明:示例1: <result name="test" type="redirect-action"> ...

  6. 使用JAVA反射初始化数组(转)

    在做JSON解析时,遇到了在不知道数组类型的前期下,需要转化为具体类型数组的问题.可以使用JAVA的反射来做. JSONArray jsonArray = (JSONArray) entry.getV ...

  7. 【C# 反射泛型】

    C# 反射泛型 摘自:http://www.itwis.com/html/net/c/20110411/10175.html C#泛型反射和普通反射的区别,泛型反射和普通反射的区别就是泛型参数的处理上 ...

  8. hibernate Session

    转: http://kayo.iteye.com/blog/204143 Session 接口 Session 接口对于Hibernate 开发人员来说是一个最重要的接口.然而在Hibernate 中 ...

  9. contentType,pageEncoding,charset,setCharacterEncoding

    contentType,pageEncoding,charset,setCharacterEncoding HTML中的meta标签,以及HTTP Header. -------------字符集.字 ...

  10. XML注入介绍--XXE,XEE,xpath等

    XML注入指在请求的XML中插入攻击利用代码.根据不同的场景,可能会形成以下的漏洞形式: (1)XEE ----xml entity xpansion(xml实体膨胀,用于dos) 具体介绍:http ...