#LCA0000093. Những người có mã số nhỏ nhất trên đường đi (Duff in the Army)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Những người có mã số nhỏ nhất trên đường đi (Duff in the Army)
Duff in the Army
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
There are cities connected by undirected roads forming a tree. There are people with unique IDs ; person lives in city . A city may host any number of people, including zero.
For each query , consider all people living in any city on the unique path from to , including its endpoints. Sort their IDs and report up to the first smallest IDs. Print the number actually reported, then these IDs in ascending order. Print 0 if the path contains no people.
Input
The first line contains . Next are edge lines . The following line contains city IDs , then queries .
Output
For each query, print k p_1 ... p_k, where is the reported count and .
Subtasks
-
Subtask 1 (20 points): ; ; ; ; edges form a tree.
-
Subtask 2 (30 points): ; ; ; ; edges form a tree.
-
Subtask 3 (50 points): ; ; ; ; edges form a tree.
Examples
Input
5 4 5
1 3
1 2
1 4
4 5
2 1 4 3
4 5 6
1 5 2
5 5 10
2 3 3
5 3 1
Output
1 3
2 2 3
0
3 1 2 4
1 2
Explanation
Person IDs live in cities , respectively. Path contains only ID ; path contains IDs ; path has no residents. Path contains IDs . The last query asks for only the smallest ID on path , namely .