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_Collections工具类

    Collections 工具类 * Collection与Collections区别 Collection 接口,(大部分集合类的实现接口) Collections 工具类(针对列表) * Colle ...

  2. Redis 持久化之RDB和AOF

    Redis 持久化之RDB和AOF Redis 有两种持久化方案,RDB (Redis DataBase)和 AOF (Append Only File).如果你想快速了解和使用RDB和AOF,可以直 ...

  3. JavaScript 中的相等操作符 ( 详解 [] == []、[] == ![]、{} == !{} )

    ECMAScript 中的相等操作符由两个等于号 ( == ) 表示,如果两个操作数相等,则返回 true. 相等操作符会先转换操作数(通常称为强制转型),然后比较它们的相等性. 在转换不同的数据类型 ...

  4. Spider-three

    一.selenium from selenium import webdriver driver = webdriver.Chrome() # 创建一个chrome浏览器控制对象#driver = w ...

  5. elementUI vue table status的状态列颜色变化和操作列状态显示(停用, 启用)

    <div id="app" style="display: none"> ... <el-table-column prop="st ...

  6. CSS3布局之box-flex的使用

    语法: box-flex:<number> 其中number取值:使用浮点数指定对象所分配其父元素剩余空间的比例.设置或检索伸缩盒对象的子元素如何分配其剩余空间.(伸缩盒最老版本) htm ...

  7. Nginx 图片服务器

    文件服务器:后台如果是集群,每次请求都会到不同的服务器,所以每台服务器的图片文件等都要做同步处理,才能保证每次用户不管访问到哪台服务器都能获取一样的资源.这种做法开销会很大,专门使用 nginx 作为 ...

  8. Redis 开启远程连接

    默认 bind 127.0.0.1 即绑定本机 IP,只能本机访问,你也可以绑定别的 IP 地址,如果注释掉,表示不限制 IP,所有 IP 都能访问 # ~~~ WARNING ~~~ If the ...

  9. 22.Odoo产品分析 (三) – 人力资源板块(3) – 休假管理(1)

    查看Odoo产品分析系列--目录 安装休假管理模块,出现"休假"菜单:  休假管理为了更方便直观的看出员工的休假信息,将信息以日历视图显示出来.  在日历中点击某一天时,可以创建改 ...

  10. Python_json数据检索与定位之jsonPath类库

    json数据检索与定位之jsonPath类库   by:授客 QQ:1033553122 实践环境 win7 64 Python 3.4.0 jsonpath_ng-1.4.3-py2.py3-non ...