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. css3巧用选择器配合伪元素

    一 . 前言 有时我们在写底部导航栏时,会有很多超链接,每个链接间用“|”分割,如下图: 可能刚入门的朋友会想到这样完成,再单独设置span的样式, 今天主要介绍怎么样用css3简单快速的完成这个效果 ...

  2. 使用EF保存数据时 提示: 其他信息: 对一个或多个实体的验证失败。有关详细信息,请参阅“EntityValidationErrors”属性。

    错误提示: 解决方法: →使用try...catch捕获→在catch所在行打上断点,运行,对ex添加监视或者运行到ex的时候  按Shift+f9天假快速监视→在EntityValidationEr ...

  3. MySQL添加新用户、为用户创建数据库、为新用户分配权限

    登录MySQL [root@VM_0_2_33_centos /]#mysql -u root -p 添加新用户 允许本地 IP 访问 localhost, 127.0.0.1 mysql>'; ...

  4. IP 协议

    在网络层中,使用的是 ip 协议,它规定网络地址的协议. ip 地址分为两个部分: 网络部分:标识子网 主机部分:标识主机 子网掩码 表示子网络特征的一个参数,它规定 网络部分全部为1,主机部分全部为 ...

  5. P1993 小 K 的农场

    题目描述 小 K 在 Minecraft 里面建立很多很多的农场,总共 n 个,以至于他自己都忘记了每个 农场中种植作物的具体数量了,他只记得一些含糊的信息(共 m 个),以下列三种形式描 述: 农场 ...

  6. cf1121F. Compress String(后缀自动机)

    题意 题目链接 Sol 居然出个SAM板子也是没谁了233 #include<bits/stdc++.h> #define Pair pair<int, int> #defin ...

  7. 华为P20无线投屏到电脑 绝地求生投射电脑

    如今出门在外,必不可少的就是手机,如果没有了手机,每个人都会感觉没有安全感,感觉和世界失去了联系,我们每天每个人都在使用手机,但是作为华为手机用户的你,了解华为P20无线投屏到电脑是怎么操作的吗? 使 ...

  8. Linux网络设备驱动的实现

    结论: 1.对一个设备驱动而言,主要从两个方面进行着手,一个是控制流,一个是数据流. 控制流就是如何控制网络设备,数据流则说的是报文的收发流程. 2.网络设备可以是Linux服务器的网卡,也可以是嵌入 ...

  9. iOS ----------要学习的地方(链接整理)

    1.http://www.cocoachina.com/special/xcode/ 2.http://blog.csdn.net/a416863220/article/details/4111387 ...

  10. loadrunner 脚本录制-Protocol Advisor协议分析器的使用

    脚本录制-Protocol Advisor协议分析器的使用 by:授客 QQ:1033553122 1.启动Protocol Advisor File > Protocol Advisor &g ...