FOJ 1635 Commandos

来源:互联网 发布:淘宝客怎么查看卖家id 编辑:程序博客网 时间:2024/05/20 19:28
Commandos
A group of commandos were assigned a critical task. They are to destroy an enemy head quarter. The enemy head quarter consists of several buildings and the buildings are connected by roads. The commandos must visit each building and place a bomb at the base of each building. They start their mission at the base of a particular building and from there they disseminate to reach each building. The commandos must use the available roads to travel between buildings. Any of them can visit one building after another, but they must all gather at a common place when their task in done. In this problem, you will be given the description of different enemy headquarters. Your job is to determine the minimum time needed to complete the mission. Each commando takes exactly one unit of time to move between buildings. You may assume that the time required to place a bomb is negligible. Each commando can carry unlimited number of bombs and there is an unlimited supply of commando troops for the mission.

Input

The first line of input contains a number T<50, where T denotes the number of test cases. Each case describes one head quarter scenario. The first line of each case starts with a positive integer N≤100, where N denotes the number of buildings in the head quarter. The next line contains a positive integer R, where R is the number of roads connecting two buildings. Each of the next R lines contain two distinct numbers, 0 ≤ u,v < N, this means there is a road connecting building u to building v. The buildings are numbered from 0 to N-1. The last line of each case contains two integers 0 ≤ s,d < N. Where s denotes the building from where the mission starts and d denotes the building where they must meet.
You may assume that two buildings will be directly connected by at most one road. The input will be such that, it will be possible to go from any building to another by using one or more roads.

Output

For each case of input, there will be one line of output. It will contain the case number followed by the minimum time required to complete the mission. Look at the sample output for exact formatting.

Sample Input

2430 12 11 30 3210 11 0

Sample Output

Case 1: 4Case 2: 1
题目大意:有一群突击队员要去炸掉敌军司令部,队员可以分开行动。但是要求必须把每个建筑物都炸掉。
最后队员在指定地点回合,完成任务。求出完成任务的最短时间是多少。
解题思路:这是一个求任意两点最短路径的问题,用到Floyd算法,然后寻找从起点出发,然后回到终点的
最长路径是多少,输出路径长度即可。
 
原创粉丝点击