Problem G
Trafikverket's Mistake
Languages
en
sv
The unthinkable has happened! The plan laid by the traffic department (Trafikverket1) has gone awry. Just before people were about to leave work in the small town of Lönnköping, a horrendous snowstorm knocked out all the internet in the town. Since the internet is down, they can’t get the latest information about Trafikverket’s Plan, and therefore can’t drive home without risking a crash.
It is now your job to find a way for everyone to get home
without any collisions. Lönnköping’s road network consists of
Thanks to the data collection that took place before the creation of Trafikverket’s Plan, you know where each person is located (they are all at work, and you know where they work) and which house they want to go home to. Right now, each person is sitting in their car outside their workplace, blocking other cars from passing by that house. To get everyone home safely, you will use a drone that flies around and tells people to “drive home”. They will then drive home along the shortest path between their workplace and their home without stopping. Once they are home, they will park their car in their garage and no longer block any roads. Due to the cold, the drone is so slow that you can assume that each person has sufficient time to drive home and park before the drone reaches the next person.
If a car ever starts driving home and there is another car in the way, they will collide due to the slippery road conditions. Determine if there is an order in which the cars can drive home that is completely free from collisions. If such an order exists, find it.
Input
The first line of the input contains two integers,
The following
After that, there are
Output
If there is an order in which the residents can drive home
without collisions, first output “Yes”. Then, print out the order in which the
residents should drive home. The resident represented first in
the input corresponds to
If there is no order without collisions, output “No”.
Points
Your solution will be tested on several test case groups. To get the points for a group, it must pass all the test cases in the group.
Group |
Point value |
Constraints |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
No additional constraints. |
Sample Input 1 | Sample Output 1 |
---|---|
5 4 1 2 2 3 2 4 4 5 5 3 4 3 3 2 1 3 |
Yes 3 4 2 1 |
Sample Input 2 | Sample Output 2 |
---|---|
4 2 1 2 2 3 3 4 2 4 3 1 |
No |
Footnotes
- See https://open.kattis.com/problems/trafikverketsplan