N . Inspector’s Dilemma

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.

Samples

Input
5 3 1
1 2
1 3
4 5
4 4 1
1 2
1 4
2 3
3 4
0 0 0
Output
Case 1: 4
Case 2: 4

题目大意:

给定n个城市,每两个个城市间有一条双向的长度为t的路,在给出m条路,要求用最短的路程走完给出的路。

思路:

给出的路是必须走的,再找出给出的路和城市组成了多少连通块(只有单个城市不算),在两个连通块间在走一条路就能使两个连通块连通(ans+=连通块的数量-1).对于每一个连通块来讲,考虑一笔画问题,必须构成欧拉通路。如果有大于2个奇数度点,没增加一条边可以减少两个奇数度点(ans+=(奇数度点数量-2)/2)。

代码:

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,m,l,x,y,a[1001][1001],d[1001],f[1001],t,tt=1;
void dfs(ll i)
{
	f[i]=0;
	if(d[i]%2)	t++;
	for(ll j=1;j<=n;j++)
		if(f[j]&&a[i][j])
			dfs(j);
}
int main()
{
	while(cin>>n>>m>>l,n+m+l)
	{
		ll ans=m;
		memset(d,0,sizeof(d));
		memset(a,0,sizeof(a));
		memset(f,0,sizeof(f));
		for(ll i=0;i<m;i++)
		{
			cin>>x>>y;
			a[x][y]=a[y][x]=1;
			d[x]++;
			d[y]++;
			f[x]=1;
			f[y]=1;
		}
		for(ll i=1;i<=n;i++)
		{
			if(!f[i])	continue;
			t=0;
			dfs(i);
			ans++;
			if(t>2)	ans+=(t-2)/2;
		}
		if(ans)	ans--;
		cout<<"Case "<<tt++<<": "<<ans*l<<endl;
	} 
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
根据提供的引用内容,"Caused by: java.lang.ClassNotFoundException: org.yaml.snakeyaml.inspector.TagInspector" 是一个Java类找不到的异常。这个异常通常发生在运行Java程序时,当程序试图加载一个类但找不到该类时会抛出此异常。 解决这个异常的方法有以下几种: 1. 确保相关的依赖库已经正确添加到项目中。在这种情况下,可能是缺少了snakeyaml库的依赖。可以通过在项目的构建文件(如pom.xml或build.gradle)中添加相应的依赖来解决这个问题。 2. 检查类路径是否正确设置。如果类路径设置不正确,Java虚拟机可能无法找到所需的类。可以通过检查类路径设置并确保它包含了所需的库和类来解决这个问题。 3. 检查类名是否正确。在这种情况下,可能是类名拼写错误或者类名发生了变化。可以通过检查类名的拼写和确保它与实际的类名匹配来解决这个问题。 4. 检查类是否在正确的位置。如果类文件不在预期的位置,Java虚拟机将无法找到它。可以通过检查类文件的位置并确保它在正确的位置来解决这个问题。 5. 检查类是否被正确地导入。如果类没有被正确地导入到代码中,Java编译器将无法找到它。可以通过检查导入语句并确保它包含了所需的类来解决这个问题。 这些是解决"Caused by: java.lang.ClassNotFoundException: org.yaml.snakeyaml.inspector.TagInspector"异常的一些常见方法。根据具体情况,可能需要采取不同的解决方法。如果以上方法都无法解决问题,可能需要进一步调查和排查。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值