Watchcow
题目大意:
给你一幅连通的图,要求从起点1开始走,要经过每条边刚好两次,并且最终回到1起点。
思路:将无向图转换成有向图求欧拉回路。
#include<cstdio>
#define N 11000
#define M 110000//由于是将无向图转换成有向图,所以边变为原来的两倍。
//因此*2,这个地方调了好几天,满满的都是泪啊。
int n,m;
struct map
{
int tot;
int head[N],v[M],pre[M];
/*
pre[]里存的是a点连得另一个点的编号。
v[]存的是当前边连得b点。
*/
bool f[M];
void addedge(int a,int b)
{
tot++;
v[tot]=b;
pre[tot]=head[a];
head[a]=tot;
}
}G;
void dfs(int now)
{
for (int p=G.head[now];p;p=G.pre[p])
{
if (!G.f[p])
{
G.f[p]=;
dfs(G.v[p]);
}
}
printf("%d\n",now);
}
int main()
{
scanf("%d%d",&n,&m);
for (int i=;i<=m;i++)
{
int a,b;
scanf("%d%d",&a,&b);
G.addedge(a,b);
G.addedge(b,a);
}
dfs();
return ;
}
Watchcow的更多相关文章
- [欧拉] poj 2230 Watchcow
主题链接: http://poj.org/problem? id=2230 Watchcow Time Limit: 3000MS Memory Limit: 65536K Total Submi ...
- POJ2230 Watchcow【欧拉回路】
Watchcow Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 6172Accepted: 2663 Special Judge ...
- POJ22230 Watchcow (欧拉回路)
Watchcow Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 6477 Accepted: 2823 Specia ...
- POJ 2230 Watchcow(有向图欧拉回路)
Bessie's been appointed the new watch-cow for the farm. Every night, it's her job to walk across the ...
- POJ 2230 Watchcow (欧拉回路)
Watchcow Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 5258 Accepted: 2206 Specia ...
- 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 ...
- POJ 2230 Watchcow 【欧拉路】
Watchcow Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 6336 Accepted: 2743 Specia ...
- 欧拉回路输出(DFS,不用回溯!)Watchcow POJ 2230
Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 8109 Accepted: 3551 Special Judge D ...
- POJ 2230 Watchcow
Watchcow Time Limit: 3000ms Memory Limit: 65536KB This problem will be judged on PKU. Original ID: 2 ...
- POJ 2230 Watchcow 欧拉图
Watchcow Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 8800 Accepted: 3832 Specia ...
随机推荐
- Virtualization API之libvirt
The virtualization API 之开源 libvirt探究 By Ruiy: libvirt supports Hypervisors(注,相关的hypervisors项目的权威网站已经 ...
- js 魔鬼训练
1.Object.assign 偷梁换柱 / 融合 - 将多个对象合并到第一个对象中去.这样一来methods对象中就包含着data对象了.否则this无法正常访问data中的title var ne ...
- Lucene简介
1 lucene简介1.1 什么是lucene Lucene是一个全文搜索框架,而不是应用产品.因此它并不像www.baidu.com 或者google Desktop那么拿来就能用,它只是提供 ...
- mongo 多条件 查询
var query1 = Query<BaseManagerForCompanyModel>.EQ(q => q.sGuidBaseCompany, sGuidBaseCompany ...
- Windows环境下安装IPython NoteBook
本文的环境:64位windows8,32位python2.7.首先你要保证电脑上装有python,并且设置成环境变量. 1.windows命令行进入到python目录下的Scripts文件,或者在该目 ...
- Note | javascript权威指南[第六版] 第2章:词法结构
语法结构规定了诸如变量名是什么样的.怎么写注释,以及程序语句之间如何分隔等规则.本章用很短的篇幅来介绍JavaScript的词法结构. 2.1.字符集 JavaScript程序是用Unic ...
- Linux后台开发面试问题汇总
个人从事安全后台开发,当然是linux环境下的了.举几个常见的问题.1. 数据结构基础.比如实现一个最简单的哈希表.2. 操作系统基础.linux进程模型,堆/栈的区别,大概的位置,各往哪个方向生长, ...
- 从实践谈iOS生命周期
从实践谈iOS生命周期 个人感觉生命周期无论在Android,还是iOS都是很重要的概念,因为在每个声明周期的状态下我们可以做很多预加载或者处理的操作.因此在这里主要总结下ViewController ...
- ie兼容CSS3渐变写法
在css3之前要想做背景色渐变就只能采用添加背景图片的方法,但是随着css3:linear-gradient属性的出现,就可以避免使用添加背景图片的方法,从而优化了性能.但是inear-gradien ...
- sql查阅每一月的数据
因为项目中需要做数据报表的功能,需要统计每个月的销售额.我找到下面的sql语句.后来经过自己的测试,发现第二句才是可以用的, //String sql="SELECT year(buydat ...