#593
Unrated
Breakdown
시간 제한
2s
메모리 제한
1024MB
제출
0
정답
0
맞힌 사람
0
정답 비율
0.0%

문제

Note: the time limit for this problem is 3s, 50% larger than the default.

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 11) to the fields (located at node NN) traveling along exactly KK 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 NN vertices (1N3001\le N\le 300) with N2N^2 edges: one edge for every pair (i,j)(i, j) for 1i,jN1 \le i, j \le N (note that there are NN self loops). After each removal, output the minimum weight of any path from 11 to NN that passes through exactly KK (not necessarily distinct) edges (2K82\le K\le 8). Note that after the ii-th removal, the graph has N2iN^2-i 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 11 and NN.

입력

The first line contains NN and KK.

The next NN lines contain NN integers each. The jj-th integer of ii-th line is wijw_{ij} (1wij1081\le w_{ij}\le 10^8).

Then N2N^2 additional lines follow, each containing two integers ii and jj (1i,jN1\le i,j\le N). Every pair of integers appears exactly once.

출력

Exactly N2N^2 lines, the minimum weight KK-path after each removal. If no KK-path exists then output 1-1.

예제 입력 1

3 4
10 4 4
9 5 3
2 1 6
3 1
2 3
2 1
3 2
2 2
1 3
3 3
1 1
1 2

예제 출력 1

11
18
22
22
22
-1
-1
-1
-1

점수

For 2T142\le T\le 14, test case TT satisfies K=(T+3)/2K=\lfloor (T+3)/2\rfloor.

코드 제출

코드를 제출하려면 로그인이 필요합니다.

로그인
내 제출
제출 내역이 없습니다.
맞은 사람
아직 맞은 사람이 없습니다.
난이도 투표
Unrated0명 투표
로그인 후 AC 받으면 투표할 수 있습니다.
전체 제출
제출 내역이 없습니다.