Under construction

Still being built. Things may change

Conference Rides

Interview

Time limit1sMemory limit2048 MB

Summary
Assign each carless attendee to one driver so that the time until every attendee reaches home is minimized.
Level

Medium5 of 10

Topics
Binary search, Graph
Solved
No attempts yet

Problem

There are nn attendees at a conference, numbered 11 through nn. Each of the first mm attendees (numbered 11 through mm) has a car to drive home after the event. The remaining n−mn - m attendees have no car and must get a ride home from the first mm attendees. Each attendee with a car can pick up at most one other attendee from attendees m+1m + 1 through nn, drive them home, and then drive to their own home.

You are given a distance matrix DD of size (n+1)×(n+1)(n+1) \times (n+1) covering the nn attendees' homes and the conference hall. For 1≤i≤n1 \le i \le n, location ii is the home of attendee ii, and location n+1n+1 is the conference hall. D[i][j]D[i][j] is the estimated travel time from location ii to location jj.

Assign drivers to passengers so that the time until every attendee has reached home is minimized.

Input

The input starts with a line containing two integers nn and mm (1≤n≤5001 \le n \le 500, 1≤m≤n1 \le m \le n). It is guaranteed that 2m≥n2m \ge n.

The next n+1n+1 lines each contain n+1n+1 integers. The jjth number on the (i+1)(i+1)th line is D[i][j]D[i][j] (0≤D[i][j]≤1080 \le D[i][j] \le 10^8). D[i][i]=0D[i][i] = 0 for all ii, and D[i][k]≤D[i][j]+D[j][k]D[i][k] \le D[i][j] + D[j][k] for all ii, jj, kk. DD is not necessarily symmetric.

Output

On the first line, print the minimum time until all attendees have arrived home.

On each of the next mm lines, print a non-negative integer tit_i for 1≤i≤m1 \le i \le m. If ti=0t_i = 0, attendee ii drives directly home without picking anyone up. If ti>0t_i > 0, attendee ii picks up attendee tit_i, drives them home, and then drives home. Each attendee without a car must be picked up by exactly one car.

Examples1

  1. Example 1

    Input
    3 2
    0 1 1 2
    2 0 1 3
    4 2 0 4
    4 3 2 0
    
    Expected output
    4
    0
    3