Problem UVA12188-Inspector's Dilemma

Time Limit: 3000 mSec

Problem Description

In a country, there are a number of cities. Each pair of city is connected by a highway, bi-directional of course. A road-inspector’s task is to travel through the highways (in either direction) and to check if everything is in order. Now, a road-inspector has a list of highways he must inspect. However, it might not be possible for him to travel through all the highways on his list without using other highways. He needs a constant amount of time to traverse any single highway. As you can understand, the inspector is a busy fellow does not want to waste his precious time. He needs to know the minimum possible time to complete his task. He has the liberty to start from and end with any city he likes. Please help him out.

 Input

The input file has several test cases. First line of each case has three integers: V (1 ≤ V ≤ 1000), the number of cities, E (0 ≤ E ≤ V ∗(V −1)/2), the number of highways the inspector needs to check and T (1 ≤ T ≤ 10), time needed to pass a single highway. Each of the next E lines contains two integers a and b (1 ≤ a,b ≤ V , a ̸= b) meaning the inspector has to check the highway between cities a and b. The input is terminated by a case with V = E = T = 0. This case should not be processed.

 Output

For each test case, print the serial of output followed by the minimum possible time the inspector needs to inspect all the highways on his list. Look at the output for sample input for details.

 Sample Input

5 3 1
1 2
1 3
4 5
4 4 1
1 2
1 4
2 3
3 4
0 0 0
 

 Sample Ouput

Case 1: 4

Case 2: 4

题解:第一次感到用vector实现邻接表比用链式前向星在有的方面好一些。

原来因为效率原因基本不用vector实现,这个题中需要统计度数所以用vector就很方便了,否则还要遍历连出去的边,计数,相对麻烦。

言归正传,这个题思路不难想到,根据题中给出的边,图中形成了一个个联通块,这道题明显是欧拉路径的情况下最短,统计每一个联通块中度数为奇数的点的个数n,这样的点都需要构造一条边使其度数为偶数,最终要的是欧拉路径而不是回路,因此所有联通块的奇度数点-2是需要构造边的点,这些点之间连边,再加上必须的e条即为答案。

 #include <iostream>
#include <vector>
#include <cstring>
#include <cstdio>
#include <cstdlib>
using namespace std; const int maxn=; int v,e,t,cnt;
bool vis[maxn];
vector<int> gra[maxn]; void dfs(int cur){
if(vis[cur]) return;
vis[cur]=true;
cnt += (int)gra[cur].size()&;
for(int i = ;i < gra[cur].size();i++){
dfs(gra[cur][i]);
}
return;
} int solve(){
int ans=;
for(int i=;i<=v;++i){
if(!vis[i] && !gra[i].empty()){
cnt=;
dfs(i);
ans+=max(cnt,);
}
}
return t*(max(ans/-,)+e);
} int iCase = ; int main()
{
//freopen("input.txt","r",stdin);
while(scanf("%d%d%d",&v,&e,&t) && (v||e||t)){
for(int i = ;i <= v;i++){
gra[i].clear();
}
memset(vis,,sizeof(vis));
for(int i=;i<e;++i){
int a,b;
scanf("%d%d",&a,&b);
gra[a].push_back(b);
gra[b].push_back(a);
}
printf("Case %d: %d\n",iCase++,solve());
}
return ;
}

UVA12188-Inspector's Dilemma(欧拉回路+连通性判断)的更多相关文章

  1. poj 2337 && zoj 1919 欧拉回路+连通性判断

    题目要求按字典序排列,而且可能有重边 所以一开始就将数组从大到小排列,那么我将字符串加入链表时就会令小的不断前移,大的被挤到后面 这里有一点问题就是我一开始使用的是qsort: int cmp(con ...

  2. UVA 12118 Inspector's Dilemma(连通性,欧拉路径,构造)

    只和连通分量以及度数有关.不同连通分量只要连一条边就够了,连通分量为0的时候要特判.一个连通分量只需看度数为奇的点的数量,两个端点(度数为奇)是必要的. 如果多了,奇点数也一定是2的倍数(一条边增加两 ...

  3. HDU 1878 欧拉回路(判断欧拉回路)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1878 题目大意:欧拉回路是指不令笔离开纸面,可画过图中每条边仅一次,且可以回到起点的一条回路.现给定一 ...

  4. UVA-12118 Inspector's Dilemma (欧拉回路)

    题目大意:一个有v个顶点的完全图,找一条经过m条指定边的最短路径. 题目分析:当每条边仅经过一次时,路径最短.给出的边可能构成若干棵树.在一棵树中,奇点个数总为偶数,若一棵树的奇点个数为0,则这棵树可 ...

  5. UVA - 12118 Inspector's Dilemma(检查员的难题)(欧拉回路)

    题意:有一个n个点的无向完全图,找一条最短路(起点终点任意),使得该道路经过E条指定的边. 分析: 1.因为要使走过的路最短,所以每个指定的边最好只走一遍,所以是欧拉道路. 2.若当前连通的道路不是欧 ...

  6. 混合欧拉回路的判断(Dinic)

    POJ1637 Sightseeing tour Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 7483   Accepte ...

  7. POJ2513(字典树+图的连通性判断)

    //用map映射TLE,字典树就AC了#include"cstdio" #include"set" using namespace std; ; ;//26个小 ...

  8. LOJ-10106(有向图欧拉回路的判断)

    题目链接:传送门 思路: (1)将每个单词视为有向路径,单词的起始字母是起始节点,末尾字母是终止节点,然后找由字母建立的有向图 是否是欧拉图或者半欧拉图. (2)先用并查集判断是否连通,再判断入度与出 ...

  9. Inspector's Dilemma(欧拉通路)

    In a country, there are a number of cities. Each pair of city is connected by a highway, bi-directio ...

随机推荐

  1. 我是这样搞懂一个神奇的BUG

    摘要: 通过分析用户的行为,才想得到为什么会出现这种情况! 前两天在BearyChat收到这样的一个报警消息: 409 ?Conflict ? 平时很少遇到这样的错误,貌似很严重的样子,吓得我赶紧查看 ...

  2. Your local changes to the following files would be overwritten by merge:

    在服务器改动之后,用sourcetree提交会产生冲突,解决办法:

  3. loj#6032. 「雅礼集训 2017 Day2」水箱(并查集 贪心 扫描线)

    题意 链接 Sol 神仙题+神仙做法%%%%%%%% 我再来复述一遍.. 首先按照\(y\)坐标排序,然后维护一个扫描线从低处往高处考虑. 一个连通块的内状态使用两个变量即可维护\(ans\)表示联通 ...

  4. 洛谷P1792 [国家集训队]种树(链表 贪心)

    题意 题目链接 Sol 最直观的做法是wqs二分+dp.然而还有一种神仙贪心做法. 不难想到我们可以按权值从大到小依次贪心,把左右两边的打上标记,但这显然是错的比如\(1\ 231\ 233\ 232 ...

  5. 【Wyn Enterprise BI知识库】 什么是商业智能 ZT

    商业智能(Business Intelligence,BI),又称商务智能,指用现代数据仓库技术.在线分析处理技术.数据挖掘和数据展现技术进行数据分析以实现商业价值. 图1:商业智能(BI)系统 商业 ...

  6. 微信小程序开发之初探

    本文是以一个简单的小例子,来简要讲解微信小程序开发步骤,希望促进学习分享. 概念 微信小程序,简称小程序,缩写xcx,英文mini program.是一种不需要下载安装即可使用的应用,它实现了应用“触 ...

  7. C# 实现截图软件功能

    本文是利用C# 开发截图软件的小例子,以供学习分享使用. 思路: 截取屏幕图片. 获取要截取的范围,即左上角,右下角坐标 填充到PictureBox中. 笔触功能,荧光笔,矩形,橡皮擦,复制,保存功能 ...

  8. leetcode-67.二进制求和

    leetcode-67.二进制求和 Points 数组 数学 题意 给定两个二进制字符串,返回他们的和(用二进制表示). 输入为非空字符串且只包含数字 1 和 0. 示例 1: 输入: a = &qu ...

  9. weui textarea超出字符被截断

    HTML: <div class="weui-cells weui-cells_form" style="margin-top: 0;"> < ...

  10. 语句调优基础知识-set statistics profile on

    set statistics profile on 获取语句真实的执行计划信息 set statistics profile on go select distinct Productid,unitp ...