Breakdown
시간 제한3초메모리 제한1024 MB
완전 방향 그래프에서 간선을 하나씩 지울 때마다 정확히 K개의 간선을 사용하는 1번 노드에서 N번 노드까지의 최소 가중치 경로를 출력한다.
문제
Farmer John's farm can be represented as a directed weighted graph, with roads (edges) connecting different nodes, and the weight of each edge being the time required to travel along the road. Every day, Bessie likes to travel from the barn (located at node ) to the fields (located at node ) traveling along exactly roads, and wants to reach the fields as quickly as possible under this constraint. However, at some point, the roads stop being maintained, and one by one, they start breaking down, becoming impassable. Help Bessie find the shortest path from the barn to the fields at all moments in time!
Formally, we start with a complete weighted directed graph on vertices () with edges: one edge for every pair for (note that there are self loops). After each removal, output the minimum weight of any path from to that passes through exactly (not necessarily distinct) edges (). Note that after the -th removal, the graph has edges left.
The weight of a path is defined as the sum of the weights of all of the edges on the path. Note that a path can contain multiple of the same edge and multiple of the same vertex, including vertices and .
입력
The first line contains and .
The next lines contain integers each. The -th integer of -th line is ().
Then additional lines follow, each containing two integers and (). Every pair of integers appears exactly once.
출력
Exactly lines, the minimum weight -path after each removal. If no -path exists then output .
힌트
After the first removal, the shortest -path is:
1 -> 2 -> 3 -> 2 -> 3
After the second removal, the shortest -path is:
1 -> 3 -> 2 -> 1 -> 3
After the third removal, the shortest -path is:
1 -> 3 -> 3 -> 3 -> 3
After six removals, there is no longer a -path.