#P14700. [ICPC 2024 Tehran R] Conference Rides

[ICPC 2024 Tehran R] Conference Rides

题目描述

There are nn attendees in a conference, numbered 1 through nn. Each of the first mm attendees (numbered 1 through mm) has a car to drive home after the event. The remaining nmn - m attendees who do not have a car, are going to get a ride to their homes with the help of the first mm attendees. Each of the first mm attendees can pick up at most one other attendee (from attendees m+1m+1 to nn) and drive them to their house before going to their own home. You are given the distance matrix DD of the n+1n+1 locations (the conference hall and nn attendees' homes). Find a way for attendees with cars to drive the attendees without cars home, such that the time it takes for all attendees to arrive at their homes is minimized. The distance matrix DD is an (n+1)×(n+1)(n+1) \times (n+1) matrix where D[i][j]D[i][j] denotes the estimated time of transportation from location ii to location jj. Location ii (for 1in1 \leq i \leq n) denotes the home of the ithi^{th} attendee and the conference hall is positioned at location n+1n+1.

输入格式

The input starts with a line containing two integers nn and mm, (1n5001 \leq n \leq 500 and 1mn1 \leq m \leq n). It is guaranteed that 2mn2m \geq n.

The following n+1n+1 lines specify the distance matrix DD, each containing n+1n+1 integers. The jthj^{th} number from the i+1thi+1^{th} line of the input (for 1i,jn+11 \leq i, j \leq n+1) specifies D[i][j]D[i][j] (0D[i][j]1080 \leq D[i][j] \leq 10^8). It is guaranteed that D[i][k]D[i][j]+D[j][k]D[i][k] \leq D[i][j] + D[j][k] for any 1i,j,kn+11 \leq i, j, k \leq n+1, and also D[i][j]=0D[i][j] = 0 for i=ji = j, but D[i][j]D[i][j] is not necessarily equal to D[j][i]D[j][i].

输出格式

In the first line of output, print the minimum time it takes for all attendees to arrive at their homes. In the next mm lines, each line ii (for 1im1 \leq i \leq m) should contain a single non-negative integer tit_i, denoting the driving schedule of the ithi^{th} attendee. If ti=0t_i = 0, the attendee drives directly to their home without picking up any other attendees. Otherwise (ti>0t_i > 0), the ithi^{th} attendee picks up the attendee tit_i and takes them to their home before driving to their own home. Each attendee must be transferred by exactly one car.

3 2
0 1 1 2
2 0 1 3
4 2 0 4
4 3 2 0
4
0
3