cf 208C最短路

The Berland road network consists of n cities and of m bidirectional roads. The cities are numbered from 1 to n, where the main capital city has number n, and the culture capital — number 1. The road network is set up so that it is possible to reach any city from any other one by the roads. Moving on each road in any direction takes the same time.

All residents of Berland are very lazy people, and so when they want to get from city v to city u, they always choose one of the shortest paths (no matter which one).

The Berland government wants to make this country’s road network safer. For that, it is going to put a police station in one city. The police station has a rather strange property: when a citizen of Berland is driving along the road with a police station at one end of it, the citizen drives more carefully, so all such roads are considered safe. The roads, both ends of which differ from the city with the police station, are dangerous.

Now the government wonders where to put the police station so that the average number of safe roads for all the shortest paths from the cultural capital to the main capital would take the maximum value.

Input
The first input line contains two integers n and m (2 ≤ n ≤ 100, ) — the number of cities and the number of roads in Berland, correspondingly. Next m lines contain pairs of integers v i, u i (1 ≤ v i, u i ≤ n, v i ≠ u i) — the numbers of cities that are connected by the i-th road. The numbers on a line are separated by a space.

It is guaranteed that each pair of cities is connected with no more than one road and that it is possible to get from any city to any other one along Berland roads.

Output
Print the maximum possible value of the average number of safe roads among all shortest paths from the culture capital to the main one. The answer will be considered valid if its absolute or relative inaccuracy does not exceed 10 - 6.

Examples
Input
4 4
1 2
2 4
1 3
3 4
Output
1.000000000000
Input
11 14
1 2
1 3
2 4
3 4
4 5
4 6
5 11
6 11
1 8
8 9
9 7
11 7
1 10
10 4
Output
1.714285714286

#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int a[110][110];
long long b[110][110];
const int INF = 0x3f3f3f3f;
int main()
{
	int n,m;
	cin>>n>>m;
	memset(a,INF,sizeof(a));
	memset(b,0,sizeof(b));
	for(int i=0;i<m;i++)
	{
		int x,y;
		cin>>x>>y;
		a[x][y]=a[y][x]=1;
		b[x][y]=b[y][x]=1;
		
	} 
	for(int k=1;k<=n;k++)
	{
		for(int i=1;i<=n;i++)
		{
			for(int j=1;j<=n;j++)
			{
				if(a[i][j]>a[i][k]+a[k][j])
				{
					a[i][j]=a[i][k]+a[k][j];
					b[i][j]=0;
				}
				if(a[i][j]==a[i][k]+a[k][j])
				{
					
					b[i][j]+=b[i][k]*b[k][j];
				}
			}
		}
	}
	double ans=1;
	for(int i=2;i<n;i++)
	{
		if(a[1][i]+a[i][n]==a[1][n])
		{
			ans=max(ans,2.0*b[1][i]*b[i][n]/b[1][n]);
		}		
	}
	printf("%.10f\n",ans);

	
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
APM204C/208C是一种调试工具,主要用于硬件电路的调试和故障排除。 调试是在设计和制造电路过程中非常重要的一步,它可以帮助我们定位和修复电路中存在的问题,确保电路的正常运行。 APM204C/208C调试工具在这个过程中发挥了关键的作用,它具有多种功能和特性,能够帮助工程师们快速准确地找到电路中的问题。 首先,APM204C/208C调试工具具有丰富的接口和连接功能,可以与电路中的各种设备和模块进行连接,如传感器、电机、开关等。这样可以方便地观察和测量电路中的信号和数据,从而找出问题所在。 其次,APM204C/208C调试工具支持多种通信协议,如UART、I2C、SPI等,可以与不同类型的设备进行通信,并进行数据交换和调试。这样可以方便地监测和控制电路中的各种设备,进一步分析和定位问题。 此外,APM204C/208C调试工具还具有强大的数据分析和调试功能。它可以实时捕获和记录电路中的信号波形和数据,通过内置的分析工具和算法,对这些数据进行处理和分析,以找出潜在的问题和异常。 最后,APM204C/208C调试工具还支持扩展和定制,用户可以根据具体的调试需求,选择和添加适合的插件和扩展模块,以满足不同的调试任务。 总之,APM204C/208C调试工具是一种功能强大、易于使用的工具,它可以帮助工程师们快速定位和修复电路中的问题,提高调试效率和准确性。无论是在电子产品研发阶段还是在生产制造过程中,APM204C/208C调试工具都是不可或缺的利器。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值