http://poj.org/problem?id=1041 (题目链接)

题意

  给出一张无向图,求字典序最小欧拉回路。

Solution

  这鬼畜的输入是什么心态啊mdzz,这里用vector储存边,便于边的排序。瞬间变成STL常数boy →_→。

细节

  数组大小把握好。

代码

// poj1041
#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<vector>
#include<cmath>
#define LL long long
#define inf 2147483640
#define Pi acos(-1.0)
#define free(a) freopen(a".in","r",stdin),freopen(a".out","w",stdout);
using namespace std; const int maxn=2000;
struct edge {
int to,id;
friend bool operator < (const edge a,const edge b) {
return a.id<b.id;
}
};
int vis[maxn],r[maxn],s[maxn],top,rt;
vector<edge> e[maxn]; void dfs(int x) {
for (int i=0;i<e[x].size();i++) if (!vis[e[x][i].id]) {
vis[e[x][i].id]=1;
dfs(e[x][i].to);
s[++top]=e[x][i].id;
}
}
int main() {
int x,y,z;
while (scanf("%d%d",&x,&y)!=EOF && x && y) {
memset(vis,0,sizeof(vis));
for (int i=1;i<maxn;i++) e[i].clear(),r[i]=0;
rt=min(x,y);
while (x && y) {
scanf("%d",&z);
e[x].push_back((edge){y,z});
e[y].push_back((edge){x,z});
r[x]++;r[y]++;
scanf("%d%d",&x,&y);
}
int flag=0;
for (int i=1;i<maxn;i++) if (r[i]&1) {flag=1;break;}
if (flag) {puts("Round trip does not exist.");continue;}
for (int i=1;i<maxn;i++) sort(e[i].begin(),e[i].end());
top=0;
dfs(rt);
while (top) printf("%d ",s[top--]);puts("");
}
return 0;
}

  

【poj1041】 John's trip的更多相关文章

  1. 【HDOJ】2425 Hiking Trip

    优先级队列+BFS. #include <iostream> #include <cstdio> #include <cstring> #include <q ...

  2. 【BZOJ】【1022】【SHOI2008】小约翰的游戏John

    博弈论 一看题,哇这不是Nim游戏么= =直接异或起来……啊咧怎么不对? 这道题是[Anti-Nim],普通的Nim是取走最后一个就赢,这题是取走最后一个输…… 做法参见 2009年贾志豪论文< ...

  3. 【POJ3683】Priest John's Busiest Day

    题目 John is the only priest in his town. September 1st is the John's busiest day in a year because th ...

  4. 【bzoj1022】小约翰的游戏John

    Portal -->bzoj1022 Solution ​  这题其实是裸的反Nim,这里主要是为了写反Nim游戏的证明 ​  首先给出反Nim(anti-nim)的定义和结论: [定义]桌子上 ...

  5. 【BZOJ】1022: [SHOI2008]小约翰的游戏John(博弈论)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1022 好神的博弈论. 题解见dzy的blog:http://dzy493941464.is-prog ...

  6. POJ3683 Priest John's Busiest Day 【2-sat】

    题目 John is the only priest in his town. September 1st is the John's busiest day in a year because th ...

  7. 【题解】POJ1934 Trip (DP+记录方案)

    [题解]POJ1934 Trip (DP+记录方案) 题意: 传送门 刚开始我是这么设状态的(谁叫我DP没学好) \(dp(i,j)\)表示钦定选择\(i\)和\(j\)的LCS,然而你会发现这样钦定 ...

  8. POJ1041 John's trip

    John's trip Language:Default John's trip Time Limit: 1000MS Memory Limit: 65536K Total Submissions: ...

  9. 【dp】codeforces C. Vladik and Memorable Trip

    http://codeforces.com/contest/811/problem/C [题意] 给定一个自然数序列,在这个序列中找出几个不相交段,使得每个段的异或值之和相加最大. 段的异或值这样定义 ...

随机推荐

  1. 2178 表达式运算Cuties

    2178 表达式运算Cuties  时间限制: 1 s  空间限制: 32000 KB  题目等级 : 大师 Master 题解       题目描述 Description 给出一个表达式,其中运算 ...

  2. 带OUTPUT参数的CLR存储过程

    前面写了一篇<带参数的CLR存储过程>http://www.cnblogs.com/insus/p/4373605.html ,如果我们需要创建一个带OUTPUT返回值. 实现它,可以先了 ...

  3. [转]nodejs npm常用命令

    FROM : http://www.cnblogs.com/linjiqin/p/3765772.html npm是一个node包管理和分发工具,已经成为了非官方的发布node模块(包)的标准.有了n ...

  4. Integer.valueof(null)报错

    原文  http://javacat360.iteye.com/blog/2024378 主题 Java 昨天,一同事问我一个问题,估计是他前段日子面试遇到的 问题很简单,String.valueof ...

  5. 关于div标签的title属性一闪一闪不正常显示的原因

    弹出了chrome的开发工具就会出现以上问题.

  6. document.elementFromPoint在IE8下无法稳定获取当前坐标元素的解决方法

    document.elementFromPoint(e.clientX, e.clientY) document.elementFromPoint(e.clientX, e.clientY) 执行2次 ...

  7. web学习第一章

    web学习第一章   我是大概9月10日开始走上IT之路的,一开始学习了小段时间的自动化办公软件, 昨天我开始学习客户端网页编程,我了解什么是WEB,一些比较老古董的计算模式和发展历史,印象最让我深刻 ...

  8. Hibernate hbm2ddl.auto DDL语句 控制台输出的配置

    在开发中我们需要知道hbm2ddl.auto生成的SQL语句,来判断代码的正确性,现在记录配置的过程. Hibernate的DDL语句在控制台的输出配置: 一.在lib中确保只有下面的三个相关包:1) ...

  9. 【转】如何拿到半数面试公司Offer——我的Python求职之路

    原文地址 从八月底开始找工作,短短的一星期多一些,面试了9家公司,拿到5份Offer,可能是因为我所面试的公司都是些创业性的公司吧,不过还是感触良多,因为学习Python的时间还很短,没想到还算比较容 ...

  10. Eclipse调试常用技巧(转)

    Eclipse调试常用技巧 转自http://daimojingdeyu.iteye.com/blog/633824 1. 条件断点 断点大家都比较熟悉,在Eclipse Java 编辑区的行头双击就 ...