Conference Rides | 프로그래밍의 벗 PivotOJ
PivotOJ

Conference Rides

시간 제한: 1000ms메모리 제한: 2048MB출처: ICPC Asia Tehran Regional Contest 2024BOJ 33199

문제

There are nn attendees in 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 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 \le i \le n) denotes the home of the iith 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 \le n \le 500 and 1mn1 \le m \le n). It is guaranteed that 2mn2m \ge n.

The following n+1n+1 lines specify the distance matrix DD, each containing n+1n+1 integers. The jjth number from the i+1i + 1th line of the input (for 1i,jn+11 \le i, j \le n + 1) specifies D[i][j]D[i][j] (0D[i][j]1080 \le D[i][j] \le 10^8). It is guaranteed that D[i][k]D[i][j]+D[j][k]D[i][k] \le D[i][j] + D[j][k] for any 1i,j,kn+11 \le i, j, k \le 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 \le i \le m) should contain a single non-negative integer tit_i, denoting the driving schedule of the iith 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 iith 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.

예제

예제 1

입력
3 2
0 1 1 2
2 0 1 3
4 2 0 4
4 3 2 0
출력
4
0
3
코드를 제출하려면 로그인하세요.