#LCA0000084. Xây dựng tuyến đường sắt (Railway)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Xây dựng tuyến đường sắt (Railway)
Railway
Source: Baltic OI
Version: Phuoc Hung OJ Extended
Problem Statement
There are neighborhoods connected by a proposed railway tree with numbered tracks. Each of deputies names a set of 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 distinct deputies. Print their IDs in increasing order; each deputy contributes at most one request per track.
Input
First line: . Next lines: edges in their ID order. Then lines, line is .
Output
Print , the number of selected tracks, then a second line of their IDs in increasing order (an empty second line if ).
Subtasks
-
Subtask 1 (20 points): ; ; ; ; ; vertices within each list are distinct; edges form a tree.
-
Subtask 2 (30 points): ; ; ; ; ; vertices within each list are distinct; edges form a tree.
-
Subtask 3 (50 points): ; ; ; ; ; 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 needs edges ; deputy needs ; deputy needs . All four edges occur in at least two requests, so the output must list all four.