#P6572. [BalticOI 2017] Railway

    ID: 7341 远端评测题 1000ms 256MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>2017虚树差分BalticOI(波罗的海)

[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 nn cities with n1n-1 roads.
Now there are mm vice ministers, and each vice minister believes that some cities must be connected.
For example, if a vice minister wants to connect aa and cc, and there are two roads aba - b and bcb - c, 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 kk vice ministers.
The minister came to you and asked you to find these roads.

Input Format

The first line contains three integers n,m,kn, m, k, representing the number of cities, the number of vice ministers, and the minimum number of vice ministers that must select a road.
The next n1n-1 lines each contain two integers aia_i and bib_i, meaning that the ii-th road is between aia_i and bib_i.
The roads are numbered from 11 to n1n-1.
The next mm lines start with an integer sis_i, meaning that this vice minister thinks there are sis_i cities that need to be connected, followed by sis_i integers indicating which cities they are.

Output Format

The first line contains an integer rr, the number of roads that are selected by at least kk vice ministers.
The second line contains rr 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 33 vice ministers are as follows:

  • 13,23,34,451-3, 2-3, 3-4, 4-5
  • 34,463-4, 4-6
  • 232-3

The roads selected by at least 22 vice ministers are road 22 and road 33.

Constraints

This problem uses bundled testdata.

  • Subtask 1 (8 pts): n104n \le 10^4, si2×103\sum s_i \le 2 \times 10^3.
  • Subtask 2 (15 pts): n104n \le 10^4, m2×103m \le 2 \times 10^3.
  • Subtask 3 (7 pts): Each city is an endpoint of at most 22 roads.
  • Subtask 4 (29 pts): k=mk = m, si=2s_i = 2.
  • Subtask 5 (16 pts): k=mk = m.
  • Subtask 6 (25 pts): No special constraints.

For 100%100\% of the testdata, 2sin1052 \le s_i \le n \le 10^5, 1km5×1041 \le k \le m \le 5 \times 10^4, si105\sum s_i \le 10^5.

Note

Translated from BOI 2017 D1 T2 Railway.
Translator: @一只书虫仔

Translated by ChatGPT 5