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. SSM 设置静态资源处理

    使用weblogic的虚拟路径virtual-directory-mapping 在页面上展示文件服务器上的图片 <weblogic-web-app> ......省略其他部分 <c ...

  2. 鼠标滑过侧边弹出内容(JS)

    效果展示 实现原理 1. html结构: <div id="contain"> <span id="share">分享</span ...

  3. GitHub for Windows离线安装包

    国内安装github客户端,真的很痛!! 偶然找到了离线安装包,感谢作者的资源分享!!! 地址:http://download.csdn.net/download/lyg468088/8723039? ...

  4. ABP问题速查表

    如果你领导要让你一夜之间掌握ABP,并且用ABP撸一个项目出来,你很可能很快速的过了一遍ABP文档就马上动手干活了.那么这篇文章就很适合你. 这篇文章列出了很多ABP新手问的问题和解答.注:有些同学问 ...

  5. Windows 不能在本地计算机启动 OracleDBConsoleorcl的问题解决方法

    解决步骤如下: 1.开始->运行cmd 2.执行 emctl start dbconsole 输入:C:\Documents and Settings\xcl>emctl start db ...

  6. iTools(pro)下载

    http://bbs.feng.com/forum.php?mod=viewthread&tid=10225990&page=1&extra=#pid157941878 htt ...

  7. [转] Scala 中的异步事件处理

    在任何并发性应用程序中,异步事件处理都至关重要.无论事件的来源是什么(不同的计算任务.I/O 操作或与外部系统的交互),您的代码都必须跟踪事件,协调为响应它们而执行的操作.应用程序可以采用两种基本方法 ...

  8. 使用Fraps获取3D程序的FPS

    Fraps为免费软件(wiki),通过Hook OpenGL(SwapBuffer)或D3D(Present)来获取目标进程的FPS信息(32位进程注入fraps32.dll,64位注入fraps64 ...

  9. Response()的对象

    addCookie(Cookie cookie):这个方法是向Response容器中添加一个Cookie,然后服务器容器会自动的将这个Cookie回写给客户机的,至于Cookie的相关知识我们会在后面 ...

  10. iis 限制动态IP地址访问次数

    An IP Address Blocking HttpModule for ASP.NET in 9 minutes namespace YourModuleNameHere 10 { 11 publ ...