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

#LCA0000093. Những người có mã số nhỏ nhất trên đường đi (Duff in the Army)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

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 nn cities connected by n−1n-1 undirected roads forming a tree. There are mm people with unique IDs 1,2,…,m1,2,\ldots,m; person ii lives in city cic_i. A city may host any number of people, including zero.

For each query (u,v,a)(u,v,a), consider all people living in any city on the unique path from uu to vv, including its endpoints. Sort their IDs and report up to the first aa smallest IDs. Print the number kk actually reported, then these kk IDs in ascending order. Print 0 if the path contains no people.

Input

The first line contains n,m,qn,m,q. Next are n−1n-1 edge lines u,vu,v. The following line contains mm city IDs c1,…,cmc_1,\ldots,c_m, then qq queries u,v,au,v,a.

Output

For each query, print k p_1 ... p_k, where kk is the reported count and p1<p2<⋯<pkp_1<p_2<\cdots<p_k.

Subtasks

  • Subtask 1 (20 points): 1≤n,m≤351\le n,m\le 35; 1≤q≤351\le q\le 35; 1≤ci,u,v≤n1\le c_i,u,v\le n; 1≤a≤101\le a\le10; edges form a tree.

  • Subtask 2 (30 points): 1≤n,m≤12001\le n,m\le 1200; 1≤q≤12001\le q\le 1200; 1≤ci,u,v≤n1\le c_i,u,v\le n; 1≤a≤101\le a\le10; edges form a tree.

  • Subtask 3 (50 points): 1≤n,m≤1000001\le n,m\le 100000; 1≤q≤1000001\le q\le 100000; 1≤ci,u,v≤n1\le c_i,u,v\le n; 1≤a≤101\le a\le10; 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 1,2,3,41,2,3,4 live in cities 2,1,4,32,1,4,3, respectively. Path 4−54-5 contains only ID 33; path 1−51-5 contains IDs 2,32,3; path 5−55-5 has no residents. Path 2−1−32-1-3 contains IDs 1,2,41,2,4. The last query asks for only the smallest ID on path 5−4−1−35-4-1-3, namely 22.