1281 - New Traffic System
Time Limit: 2 second(s)
Memory Limit: 32 MB
The country - Ajobdesh has a lot of problems in traffic system. As the Govt. is very clever (!), they made a plan to use only one way roads. Two cities s and t are the two most important cities in the country and mostly people travel from s to t. That's why the Govt. made a new plan to introduce some new one way roads in the traffic system such that the time to travel from s to t is reduced.
But since their budget is short, they can't construct more than d roads. So, they want to construct at most d new roads such that it becomes possible to reach t from s in shorter time. Unluckily you are one living in the country and you are assigned this task. That means you will be given the existing roads and the proposed new roads, you have to find the best path from s to t, which may allow at most d newly proposed roads.
Input starts with an integer T (≤ 30), denoting the number of test cases.
Each case starts with a line containing four integers n (2 ≤ n ≤ 10000), m (0 ≤ m ≤ 20000), k (0 ≤ k ≤ 10000), d (0 ≤ d ≤ 10) where n denotes the number of cities, m denotes the number of existing roads and k denotes the number of proposed new roads. The cities are numbered from 0 to n-1 and city 0 is denoted as s and city (n-1) is denoted as t.
Each of the next m lines contains a description of a road, which contains three integers ui vi wi (0 ≤ ui, vi < n, ui ≠ vi, 1 ≤ wi ≤ 1000) meaning that there is a road from ui to vi and it takes wi minutes to travel in the road. There is at most one road from one city to another city.
Each of the next k lines contains a proposed new road with three integers ui vi wi (0 ≤ ui, vi < n, ui ≠ vi 1 ≤ wi ≤ 1000) meaning that the road will be from ui to vi and it will take wi minutes to travel in the road. There can be at most one proposed road from one city to another city.
For each case, print the case number and the shortest path cost from s to t or "Impossible" if there is no path from s to t.
2
4 2 2 2
0 1 10
1 3 20
0 2 5
2 3 14
2 0 1 0
0 1 100
Case 1: 19
Case 2: Impossible
Dataset is huge, use faster I/O methods.
思路:最短路;
这个是二维最短路,因为可以添加一些边,而且边数有限制,d[i][j]表示到0点到当前点添加条边的最短路径,用个优先队列维护的dj算法。
1 #include
2 #include
3 #include
4 #include
5 #include
6 #include
7 #include
手机扫一扫
移动阅读更方便
你可能感兴趣的文章