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. Java中关于Map的使用(HashMap、ConcurrentHashMap)

    在日常开发中Map可能是Java集合框架中最常用的一个类了,当我们常规使用HashMap时可能会经常看到以下这种代码: Map<Integer, String> hashMap = new ...

  2. python进程池

    当需要创建的子进程数量不多时,可以直接利用multiprocessing中的Process动态成生多个进程,但如果是上百甚至上千个目标,手动的去创建进程的工作量巨大,此时就可以用到multiproce ...

  3. Mac超快速搭建Nginx、PHP、PHPStorm、XDebug环境

    一.安装自己需要的版本php 以php7.1为例,执行:curl -s https://php-osx.liip.ch/install.sh | bash -s 7.1 (去这个链接下找自己想要下载的 ...

  4. Ext获取uuid

    Ext获取UUID 方法1:Ext.data.IdGenerator.get('uuid').generate() 方法2://创建一个uuid生成器uuidGenerator var uuidGen ...

  5. phpcms配置列表页以及获得文章发布时间

    <div class="moocConDetail"> {pc:content action="lists" catid="11" ...

  6. java对程序的简单加密

    File file = new File("oppo.in"); File file1 = new File("main.in"); GregorianCale ...

  7. error 2593 operator << 不明确的可能的解决方法

    编译Martinez算法时遇到该问题,提示重载的<<操作符调用不明确. 解决方法为:在cpp文件中将重载的该操作符的实现前添加完整的命名空间路径.

  8. Django+MongoDB批量插入数据

    在百万级和千万级数据级别进行插入,pymongo的insert_many()方法有着很强的优势.原因是每次使用insert_one()方法进行插入数据,都是要对数据库服务器进行一次访问,而这样的访问是 ...

  9. 关于一体机打印新加菜按钮更改为下单小票打印设置FAQ(适用正餐6.0.1.0+,轻餐4.0.6.2+)

    适用版本:正餐6.0.1.0+,轻餐4.0.6.2+ 实际场景:更新后小票设置中的打印新加菜按钮更换为下单小票打印设置,更换后,设置中,有3个选项: 1.仅打印新加菜    (选中后,订单加菜后前台小 ...

  10. nodejs 第一天

    一.nodejs 安装 略过 二.IDE :webstorm(汉化) 三.nodejs 和 js 的区别 1.在ECMAScript 部分node和js 是一样的,比如数据类型的定义,语法结构,内置对 ...