Travel Subtask 2s 1024MB
Problems
Mr. Malnar has finally reached his annual vacation. The country he decided to travel to can be represented as
Mr. Malnar routinely booked the most expensive hotel in one of the cities and then started to plan his journey. To facilitate his planning, he recorded the length of the shortest path needed from the hotel to each city.
Excited about his long-awaited vacation, Mr. Malnar completely forgot in which city the hotel is located. He certainly does not want to miss the trip, so he asks you to determine in which cities the hotel can be located.
Input
In the first line, there are natural numbers
In the
In the last line, there are
Output
In the first line, write the number of cities where the hotel can be located.
In the second line, write the labels of the cities where the hotel can be located, in ascending order.
Subtask
| # | Score | Condition |
|---|---|---|
| #1 | 9 | |
| #2 | 18 | |
| #3 | 32 | |
| #4 | 41 | No additional constraints. |
Example #1
7 6
1 2
1 3
3 4
3 5
3 6
5 7
2 -1 -1 -1 -1 -1 3
2
4 6
The path from the city labeled
The same holds true for the city labeled
Example #2
6 6
1 2
2 3
3 4
4 5
5 6
6 1
2 -1 -1 1 -1 -1
2
3 5
Example #3
4 3
1 2
2 3
3 4
1 -1 -1 1
0