关键字:最短路径,有条件限制
题目:
The country is facing a terrible civil war—-cities in the country are divided into two parts supporting different leaders. As a merchant, Mr. M does not pay attention to politics but he actually knows the severe situation, and your task is to help him reach home as soon as possible. “For the sake of safety,”, said Mr.M, “your route should contain at most 1 road which connects two cities of different camp.” Would you please tell Mr. M at least how long will it take to reach his sweet home?
输入描述:
The input contains multiple test cases.
The first line of each case is an integer N (2<=N<=600), representing the number of cities in the country.
The second line contains one integer M (0<=M<=10000), which is the number of roads.
The following M lines are the information of the roads. Each line contains three integers A, B and T, which means the road between city A and city B will cost time T. T is in the range of [1,500].

这是一道关于最短路径的编程题,要求在最多经过一条连接不同阵营城市的路线的情况下,帮助商人Mr. M从城市1到城市2。输入包含城市数量、道路信息和城市阵营,输出是最短时间或-1表示无法按要求到达。可以通过将不同阵营之间的边设置为有向边来简化问题。
最低0.47元/天 解锁文章

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



