#P6572. [BalticOI 2017] Railway
[BalticOI 2017] Railway
Background
One year ago, the Bergen Ministry of Infrastructure planned to connect all cities with roads.
Unfortunately, after a year, the project was abandoned.
So the minister decided to restart the plan and make it a bit simpler.
Problem Description
The original plan was to connect cities with roads.
Now there are vice ministers, and each vice minister believes that some cities must be connected.
For example, if a vice minister wants to connect and , and there are two roads and , then this vice minister’s requirement is equivalent to selecting these two roads.
Now you need to find which roads are selected by at least vice ministers.
The minister came to you and asked you to find these roads.
Input Format
The first line contains three integers , representing the number of cities, the number of vice ministers, and the minimum number of vice ministers that must select a road.
The next lines each contain two integers and , meaning that the -th road is between and .
The roads are numbered from to .
The next lines start with an integer , meaning that this vice minister thinks there are cities that need to be connected, followed by integers indicating which cities they are.
Output Format
The first line contains an integer , the number of roads that are selected by at least vice ministers.
The second line contains integers, the indices of these roads in increasing order.
6 3 2
1 3
2 3
3 4
6 4
4 5
4 1 3 2 5
2 6 3
2 3 2
2
2 3
Hint
Sample Explanation
The requirements of vice ministers are as follows:
The roads selected by at least vice ministers are road and road .
Constraints
This problem uses bundled testdata.
- Subtask 1 (8 pts): , .
- Subtask 2 (15 pts): , .
- Subtask 3 (7 pts): Each city is an endpoint of at most roads.
- Subtask 4 (29 pts): , .
- Subtask 5 (16 pts): .
- Subtask 6 (25 pts): No special constraints.
For of the testdata, , , .
Note
Translated from BOI 2017 D1 T2 Railway.
Translator: @一只书虫仔。
Translated by ChatGPT 5