#P14700. [ICPC 2024 Tehran R] Conference Rides
[ICPC 2024 Tehran R] Conference Rides
题目描述
There are attendees in a conference, numbered 1 through . Each of the first attendees (numbered 1 through ) has a car to drive home after the event. The remaining attendees who do not have a car, are going to get a ride to their homes with the help of the first attendees. Each of the first attendees can pick up at most one other attendee (from attendees to ) and drive them to their house before going to their own home. You are given the distance matrix of the locations (the conference hall and 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 is an matrix where denotes the estimated time of transportation from location to location . Location (for ) denotes the home of the attendee and the conference hall is positioned at location .
输入格式
The input starts with a line containing two integers and , ( and ). It is guaranteed that .
The following lines specify the distance matrix , each containing integers. The number from the line of the input (for ) specifies (). It is guaranteed that for any , and also for , but is not necessarily equal to .
输出格式
In the first line of output, print the minimum time it takes for all attendees to arrive at their homes. In the next lines, each line (for ) should contain a single non-negative integer , denoting the driving schedule of the attendee. If , the attendee drives directly to their home without picking up any other attendees. Otherwise (), the attendee picks up the attendee 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