아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Breakdown

시간 제한3초메모리 제한1024 MB

요약
완전 방향 그래프에서 간선을 하나씩 지울 때마다 정확히 K개의 간선을 사용하는 1번 노드에서 N번 노드까지의 최소 가중치 경로를 출력한다.
난이도

보통10점 중 7점

유형
행렬, 동적 계획법, 최단 경로
정답자
아직 제출이 없습니다

문제

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 (1≤N≤3001\le N\le 300) with N2N^2 edges: one edge for every pair (i,j)(i, j) for 1≤i,j≤N1 \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 (2≤K≤82\le K\le 8). Note that after the ii-th removal, the graph has N2−iN^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 w_ijw\_{ij} (1≤w_ij≤1081\le w\_{ij}\le 10^8).

Then N2N^2 additional lines follow, each containing two integers ii and jj (1≤i,j≤N1\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.

힌트

After the first removal, the shortest 44-path is:

1 -> 2 -> 3 -> 2 -> 3

After the second removal, the shortest 44-path is:

1 -> 3 -> 2 -> 1 -> 3

After the third removal, the shortest 44-path is:

1 -> 3 -> 3 -> 3 -> 3

After six removals, there is no longer a 44-path.

예제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
    
    예상 출력
    11
    18
    22
    22
    22
    -1
    -1
    -1
    -1