WuKong |
| Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) |
| Total Submission(s): 208 Accepted Submission(s): 88 |
|
Problem Description
Liyuan wanted to rewrite the famous book “Journey to the West” (“Xi You Ji” in Chinese pinyin). In the original book, the Monkey King Sun Wukong was trapped by the Buddha for 500 years, then he was rescued by Tang Monk, and began his journey to the west. Liyuan
thought it is too brutal for the monkey, so he changed the story:
One day, Wukong left his home - Mountain of Flower and Fruit, to the Dragon King’s party, at the same time, Tang Monk left Baima Temple to the Lingyin Temple to deliver a lecture. They are both busy, so they will choose the shortest path. However, there may be several different shortest paths between two places. Now the Buddha wants them to encounter on the road. To increase the possibility of their meeting, the Buddha wants to arrange the two routes to make their common places as many as possible. Of course, the two routines should still be the shortest paths. Unfortunately, the Buddha is not good at algorithm, so he ask you for help. |
|
Input
There are several test cases in the input. The first line of each case contains the number of places N (1 <= N <= 300) and the number of roads M (1 <= M <= N*N), separated by a space. Then M lines follow, each of which contains three integers a b c, indicating
there is a road between place a and b, whose length is c. Please note the roads are undirected. The last line contains four integers A B C D, separated by spaces, indicating the start and end points of Wukong, and the start and end points of Tang Monk respectively.
The input are ended with N=M=0, which should not be processed. |
|
Output
Output one line for each case, indicating the maximum common points of the two shortest paths.
|
|
Sample Input
6 6 1 2 1 2 3 1 3 4 1 4 5 1 1 5 2 4 6 3 1 6 2 4 0 0 |
|
Sample Output
3 Hint: One possible arrangement is (1-2-3-4-6) for Wukong and (2-3-4) for Tang Monk. The number of common points are 3. |
|
Source
题目大意:
给出 n m 常规意思。
然后是给出双向图 , a —> b 花费为 c
然后给出悟空的 出发点和终点,给出唐僧的出发的和终点,问他们有几个相遇的地点,两个人都是走得最短路,并且两个人如果有多条最短路
选择最短路上点多的那个走。
思路:
Floy 的过程中记录下来最短路的经过点数,代码中我用了 path 这个数组记录。
然后 最短路是一段连续的路,也就是说 如果他俩相遇,他俩就会从开始相遇的地方一直走到某个人终点,因此我们可以选择枚举
中间他们相遇的地方。
现在用数组 d [ i ] [ j ] 表示 i 到 j 的最短路,枚举方法就是:
如果当前 i -> j 悟空走过,并且唐僧也走过,那么这个就是他们的相遇的地方,一直更新下去就行了
数组一开始开的小了,超时了好久。。。0.0 尴尬
AC代码:
|
HDU 2833 WuKong 最短路
最新推荐文章于 2019-09-23 20:39:14 发布
探讨了在给定的图中寻找两条最短路径之间的最大相遇点数量问题,通过Floyd算法进行优化求解。
929

被折叠的 条评论
为什么被折叠?



