【poj1041】 John's trip
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的更多相关文章
- 【HDOJ】2425 Hiking Trip
优先级队列+BFS. #include <iostream> #include <cstdio> #include <cstring> #include <q ...
- 【BZOJ】【1022】【SHOI2008】小约翰的游戏John
博弈论 一看题,哇这不是Nim游戏么= =直接异或起来……啊咧怎么不对? 这道题是[Anti-Nim],普通的Nim是取走最后一个就赢,这题是取走最后一个输…… 做法参见 2009年贾志豪论文< ...
- 【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 ...
- 【bzoj1022】小约翰的游戏John
Portal -->bzoj1022 Solution 这题其实是裸的反Nim,这里主要是为了写反Nim游戏的证明 首先给出反Nim(anti-nim)的定义和结论: [定义]桌子上 ...
- 【BZOJ】1022: [SHOI2008]小约翰的游戏John(博弈论)
http://www.lydsy.com/JudgeOnline/problem.php?id=1022 好神的博弈论. 题解见dzy的blog:http://dzy493941464.is-prog ...
- 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 ...
- 【题解】POJ1934 Trip (DP+记录方案)
[题解]POJ1934 Trip (DP+记录方案) 题意: 传送门 刚开始我是这么设状态的(谁叫我DP没学好) \(dp(i,j)\)表示钦定选择\(i\)和\(j\)的LCS,然而你会发现这样钦定 ...
- POJ1041 John's trip
John's trip Language:Default John's trip Time Limit: 1000MS Memory Limit: 65536K Total Submissions: ...
- 【dp】codeforces C. Vladik and Memorable Trip
http://codeforces.com/contest/811/problem/C [题意] 给定一个自然数序列,在这个序列中找出几个不相交段,使得每个段的异或值之和相加最大. 段的异或值这样定义 ...
随机推荐
- 两个经典的Oracle触发器示例(轉)
[案例一] 题目:--触发器:--添加员工信息,流水号作为自动编号(通过序列生成),--并且判断如果工资小于0,则改为0;如果大于10000,则改为10000. CREATE TABLE emp2(e ...
- IntelliJ IDEA 13试用手记(附详细截图)
从去年开始转java以来,一直在寻找一款趁手的兵器,eclipse虽然是很多java程序员的首选,但是我发现一旦安装了一些插件,workspace中的项目达到数10个以后,经常崩溃,实在影响编程的心情 ...
- spring WebSocket详解
场景 websocket是Html5新增加特性之一,目的是浏览器与服务端建立全双工的通信方式,解决http请求-响应带来过多的资源消耗,同时对特殊场景应用提供了全新的实现方式,比如聊天.股票交易.游戏 ...
- PRML读书会第十一章 Sampling Methods(MCMC, Markov Chain Monte Carlo,细致平稳条件,Metropolis-Hastings,Gibbs Sampling,Slice Sampling,Hamiltonian MCMC)
主讲人 网络上的尼采 (新浪微博: @Nietzsche_复杂网络机器学习) 网络上的尼采(813394698) 9:05:00 今天的主要内容:Markov Chain Monte Carlo,M ...
- [BZOJ1016][JSOI2008]最小生成树计数(结论题)
题目:http://www.lydsy.com:808/JudgeOnline/problem.php?id=1016 分析: 首先有个性质:如果边集E.E'都可以表示一个图G的最小生成树(当然E和E ...
- poj 1698 Alice‘s Chance
poj 1698 Alice's Chance 题目地址: http://poj.org/problem?id=1698 题意: 演员Alice ,面对n场电影,每场电影拍摄持续w周,每周特定几天拍 ...
- The median of multi ascending array
Given 17 arrays,every array is ascending.The task is to get the median of all these numbers. 0 1 2 3 ...
- Bete冲刺第六阶段
Bete冲刺第六阶段 github:https://github.com/RadioGroup/JourneyHelper 今日工作: web: 陈灿:新增了用户信息更新接口,优化了部分接口逻辑,更新 ...
- ListView适配器获取布局文件作为View的三种方式
第一种方法: public View getView(int position, View convertView, ViewGroup parent) { View view = null; if ...
- 美发屋App-业余爱好
出于个人爱好, 自行设计了一款APP,由于时间有限,APP目前只做了3天,现大四,急求一份实习工作,月薪3K左右即可! 软件UI设计到编码,全部又我一人完成,所以工作量比较大 底部采用·Fragmen ...