关键是每条边必须走两遍,重复建边即可,因为确定了必然存在 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. Linux "ls -l"文件列表权限详解

    ls Linux "ls -l"文件列表权限详解 1.使用 ls -l 命令 执行结果如下(/var/log) : drwxr-x--- root adm -- : apache2 ...

  2. shell dev null 是什么

    1:在不想把标准输出和标准出错信息输出到控制台,也不想重定向到文件时经常使用 2:不能忽略其读入功能.从/dev/null读入时都是0 3:系统的垃圾桶,类似于Windows的回收站,不同的是这个设备 ...

  3. IntelliJ IDEA 15 创建maven项目

    说明 创建Maven项目的方式:手工创建 好处:参考IntelliJ IDEA 14 创建maven项目二(此文章描述了用此方式创建Maven项目的好处)及idea14使用maven创建web工程(此 ...

  4. java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver

    因为这个问题折腾了以上午,终于解决了,做下记录: 错误提示为:java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLSer ...

  5. MonthPicker

    可以只选择MMM-yyyy的样式,而不需要确定day. http://lucianocosta.info/jquery.mtz.monthpicker/

  6. POJ 3104

    Drying Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 7959   Accepted: 2014 Descriptio ...

  7. linux出现bash: ./java: cannot execute binary file 问题的解决办法

    问题现象描述: 到orcal官网上下载了两个jdk: (1)jdk-7u9-linux-i586.tar.gz ------------>32位 (2)jdk-7u9-linux-x64.tar ...

  8. hdu2015

    http://acm.hdu.edu.cn/showproblem.php?pid=2015 #include<iostream> #include<stdio.h> #inc ...

  9. 用 React 编写2048游戏

    1.代码 <!DOCTYPE html> <html lang="zh-cn"> <head> <meta charset="U ...

  10. java:访问权限-protected实例

    在不同包,子类继承后可以使用父类的protect权限的属性或方法 父类: package com.tinyphp; public class Father { protected String nam ...