PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#LCA0000084. Xây dựng tuyến đường sắt (Railway)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Xây dựng tuyến đường sắt (Railway)

Railway

Source: Baltic OI

Version: Phuoc Hung OJ Extended

Problem Statement

There are nn neighborhoods connected by a proposed railway tree with n−1n-1 numbered tracks. Each of mm deputies names a set of sis_i neighborhoods to connect. The tracks needed by one deputy are the union of all unique paths between pairs of selected neighborhoods. Build all tracks requested by at least kk distinct deputies. Print their IDs in increasing order; each deputy contributes at most one request per track.

Input

First line: n,m,kn,m,k. Next n−1n-1 lines: edges u,vu,v in their ID order. Then mm lines, line ii is si v1 … vsis_i\ v_1\ \ldots\ v_{s_i}.

Output

Print rr, the number of selected tracks, then a second line of their IDs in increasing order (an empty second line if r=0r=0).

Subtasks

  • Subtask 1 (20 points): 2≤n≤352\le n\le 35; 1≤k≤m≤351\le k\le m\le 35; 2≤si≤n2\le s_i\le n; ∑i=1msi≤250\sum_{i=1}^m s_i\le 250; 1≤vj,u,v≤n1\le v_j,u,v\le n; vertices within each list are distinct; edges form a tree.

  • Subtask 2 (30 points): 2≤n≤12002\le n\le 1200; 1≤k≤m≤12001\le k\le m\le 1200; 2≤si≤n2\le s_i\le n; ∑i=1msi≤7000\sum_{i=1}^m s_i\le 7000; 1≤vj,u,v≤n1\le v_j,u,v\le n; vertices within each list are distinct; edges form a tree.

  • Subtask 3 (50 points): 2≤n≤1000002\le n\le 100000; 1≤k≤m≤500001\le k\le m\le 50000; 2≤si≤n2\le s_i\le n; ∑i=1msi≤100000\sum_{i=1}^m s_i\le 100000; 1≤vj,u,v≤n1\le v_j,u,v\le n; vertices within each list are distinct; edges form a tree.

Examples

Input

5 3 2
1 2
2 3
2 4
4 5
2 1 3
2 3 5
2 1 5

Output

4
1 2 3 4

Explanation

Deputy 11 needs edges 1,21,2; deputy 22 needs 2,3,42,3,4; deputy 33 needs 1,3,41,3,4. All four edges occur in at least two requests, so the output must list all four.