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. iis 发布MVC HTTP错误 403.14

    1. 在web.config增加<modules runAllManagedModulesForAllRequests="true" /> 如:问题依然不能解决.报错貌 ...

  2. 错题724-java

    1.代码片段: byte b1=1,b2=2,b3,b6; final byte b4=4,b5=6; b6=b4+b5; b3=(b1+b2); System.out.println(b3+b6); ...

  3. 截取视图某一段另存为部分视图(Partial View)

    在做ASP.NET MVC后台管理程序时,根据程序需要,Isus.NET需要实现一个功能,就是动态截取视图某一段另存为部分视图Partial View. 思路为在视图中,使用jQury的程序截图以及P ...

  4. iOS开发 传感器(加速计、摇一摇、计步器)

    一.传感器 1.什么是传感器传感器是一种感应\检测周围环境的一种装置, 目前已经广泛应用于智能手机上 传感器的作用用于感应\检测设备周边的信息不同类型的传感器, 检测的信息也不一样 iPhone中的下 ...

  5. Unity 使用快速教程

    Unity是微软在CodePlex上的一个开源项目,可用于依赖注入.控制反转,类似Spring,下面是使用示例: 1.先来定义几个接口.类 namespace UnityTest { public i ...

  6. 前端见微知著番外篇:Bitbucket进行代码管控

    说道代码管控,一般都会提到TFS.Git等,但是在这里我们将要用到Bitbucket,其实其操作方式和Git基本上一样,但是和TFS则有很大的不同了.但是原理基本上都是一致的. 这里我不会过多的涉及到 ...

  7. .NET程序迁移到Mysql的极简方案——让GGTalk同时支持Sqlserver与mysql全程记录!

    园子里的这个GGTalk,咱们前前后后用它移花接木做的IM项目也不下三四个了.初次入手的时候,洋洋代码,多少感觉有些难以把握.不过一来二去,理清了头绪,也就一览无余了.相信跟我们一样想要利用GGTal ...

  8. HTC Vive 与Leap Motion 出现位置错误的问题

    Leap Motion已经支持VR, 但是官方没有支持HTC Vive的例子. 按照官方的文档, 其实是有问题的: https://developer.leapmotion.com/documenta ...

  9. nios II--实验5——定时器软件部分

    软件开发 首先,在硬件工程文件夹里面新建一个software的文件夹用于放置软件部分:打开toolsàNios II 11.0 Software Build Tools for Eclipse,需要进 ...

  10. MATLAB实现频数直方图——hist的使用

      "hist" is short for "Histogram(直方图.柱状图)". 1.N = hist(Y) bins the elements of Y ...