E. Duff in the Army
time limit per test
4 seconds
memory limit per test
512 megabytes
input
standard input
output
standard output

Recently Duff has been a soldier in the army. Malek is her commander.

Their country, Andarz Gu has n cities (numbered from 1 to n) and n - 1 bidirectional roads. Each road connects two different cities. There exist a unique path between any two cities.

There are also m people living in Andarz Gu (numbered from 1 to m). Each person has and ID number. ID number of i - th person is i and he/she lives in city number ci. Note that there may be more than one person in a city, also there may be no people living in the city.

Malek loves to order. That's why he asks Duff to answer to q queries. In each query, he gives her numbers v, u and a.

To answer a query:

Assume there are x people living in the cities lying on the path from city v to city u. Assume these people's IDs are p1, p2, ..., px in increasing order.

If k = min(x, a), then Duff should tell Malek numbers k, p1, p2, ..., pk in this order. In the other words, Malek wants to know a minimums on that path (or less, if there are less than a people).

Duff is very busy at the moment, so she asked you to help her and answer the queries.

Input

The first line of input contains three integers, n, m and q (1 ≤ n, m, q ≤ 105).

The next n - 1 lines contain the roads. Each line contains two integers v and u, endpoints of a road (1 ≤ v, u ≤ n, v ≠ u).

Next line contains m integers c1, c2, ..., cm separated by spaces (1 ≤ ci ≤ n for each 1 ≤ i ≤ m).

Next q lines contain the queries. Each of them contains three integers, v, u and a (1 ≤ v, u ≤ n and 1 ≤ a ≤ 10).

Output

For each query, print numbers k, p1, p2, ..., pk separated by spaces in one line.

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
Note

Graph of Andarz Gu in the sample case is as follows (ID of people in each city are written next to them):


【题意】给N<=100000的一颗树,M<=100000个人,Q<=100000的询问,每个人都在某个节点,一个节点可以有不定数的人,询问(u,v)上前a个编号的人是哪些?

【解题方法】倍增LCA,have[i][u],u向上爬2^i方步有多少个人,只需要维护前10个就好了,这里不能用stl的vector,会t哭,所以手写vector,但是我这个效率也很低。测了一份别人的代码,只需要500ms,我这份代码跑了2000多ms。不过毕竟也能过,按照lca往上爬,维护答案就可以了。

【AC 代码】

#include <bits/stdc++.h>
using namespace std;
const int maxn=1e5+10;
int n,m,q;
struct Myvec{
    int a[10],sz;
    Myvec(){sz=0;}
    int size(){return sz;}
    void push_back(int &x){if(sz<10) a[sz++]=x;}
    int &operator[](const int &i){return a[i];}
};
Myvec operator+(Myvec a,Myvec b){
    Myvec res;
    int i,j;
    for(i=j=0; i<a.size()&&j<b.size()&&res.size()<10;){
        if(a[i]<b[j]) res.push_back(a[i++]);
        else res.push_back(b[j++]);
    }
    while(res.size()<10&&i<a.size()) res.push_back(a[i++]);
    while(res.size()<10&&j<b.size()) res.push_back(b[j++]);
    return res;
}
vector<int>G[maxn];
Myvec c[maxn],have[17][maxn];
int dep[maxn],p[17][maxn];
void dfs(int u,int f)
{
    p[0][u]=f;
    have[0][u]=c[f];
    for(int i=1; (1<<i)<=dep[u]; i++){
        p[i][u]=p[i-1][p[i-1][u]];
        have[i][u]=have[i-1][u]+have[i-1][p[i-1][u]];
    }
    for(int i=0; i<G[u].size(); i++){
        int v=G[u][i];
        if(v==f) continue ;
        dep[v] = dep[u]+1;
        dfs(v,u);
    }
}
int lca(int u,int v)
{
    if(dep[u]>dep[v]) swap(u,v);
    for(int i=0; i<17; i++)
        if(dep[v]-dep[u]>>i&1) v=p[i][v];
    if(u==v) return u;
    for(int i=16; i>=0; i--){
        if(p[i][u]!=p[i][v]){
            u=p[i][u];
            v=p[i][v];
        }
    }
    return p[0][u];
}
Myvec gohead(int u,int _lca)
{
    Myvec ret=c[u];
    for(int i=0; i<17; i++){
        if(dep[u]-dep[_lca]-1>0 && dep[u]-dep[_lca]-1>>i&1){
            ret=ret+have[i][u];u=p[i][u];
        }
    }
    return ret;
}
int main()
{
    int u,v,a,x;
    cin>>n>>m>>q;
    for(int i=1; i<n; i++){
        cin>>u>>v;
        G[u].push_back(v);
        G[v].push_back(u);
    }
    for(int i=1; i<=m; i++)
    {
        scanf("%d",&x);
        if(c[x].size()<10) c[x].push_back(i);
    }
    dfs(1,0);
    while(q--)
    {
        cin>>u>>v>>a;
        int _lca=lca(u,v);
        Myvec ans;
        if(u!=_lca&&v!=_lca) ans=c[_lca];
        ans=ans+gohead(u,_lca);
        if(v!=u) ans=ans+gohead(v,_lca);
        int k=min(ans.size(),a);
        printf("%d ",k);
        for(int i=0; i<k; i++){
            printf("%d ",ans[i]);
        }
        printf("\n");
    }
    return 0;
}