#P10231. [COCI 2023/2024 #4] Putovanje
[COCI 2023/2024 #4] Putovanje
Background
Translated from COCI 2023/2024 Contest #4 Task 4 “Putovanje”.
Problem Description
Mr. Malnar has finally reached his annual vacation. The country he decided to visit can be represented as cities and bidirectional roads connecting them. All roads have the same length, and it is possible to travel from any city to any other city using these roads. A path from city to city is defined as a sequence of roads such that, starting from city , you traverse the roads in that order and eventually arrive at city . The length of a path is defined as the number of roads on that path.
As usual, Mr. Malnar booked the most expensive hotel in one of the cities and then started planning his trip. To make planning easier, he wrote down the shortest path length from the hotel to every city.
Because he was excited about his long-awaited vacation, Mr. Malnar completely forgot which city the hotel is in. He certainly does not want to miss this trip, so he asks you to determine which cities the hotel could be located in.
Input Format
The first line contains two integers and , representing the number of cities and roads.
The next lines each contain two integers , meaning there is a road between cities and . There is at most one road between any pair of cities.
The last line contains integers. The -th integer denotes the path length from city to the city where the hotel is located; if Mr. Malnar did not record this value, it is .
Output Format
On the first line, output how many cities the hotel could be located in.
On the second line, output the indices of the cities where the hotel could be located, in increasing order.
7 6
1 2
1 3
3 4
3 5
3 6
5 7
2 -1 -1 -1 -1 -1 3
2
4 6
6 6
1 2
2 3
3 4
4 5
5 6
6 1
2 -1 -1 1 -1 -1
2
3 5
4 3
1 2
2 3
3 4
1 -1 -1 1
0
Hint
Sample Explanation 1
The path length from city to city is , and to city is . Therefore, city satisfies both conditions, so the hotel can be located there.
The same also applies to city .
Subtasks
| Subtask ID | Additional Constraints | Score |
|---|---|---|
| , and for all , | ||
| For all , | ||
| No additional constraints |
Translated by ChatGPT 5