CF1899G.Unusual Entertainment

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

A tree is a connected graph without cycles.

A permutation is an array consisting of nn distinct integers from 11 to nn in any order. For example, [5,1,3,2,4][5, 1, 3, 2, 4] is a permutation, but [2,1,1][2, 1, 1] is not a permutation (as 11 appears twice in the array) and [1,3,2,5][1, 3, 2, 5] is also not a permutation (as n=4n = 4 , but 55 is present in the array).

After a failed shoot in the BrMeast video, Alex fell into depression. Even his birthday did not make him happy. However, after receiving a gift from Timofey, Alex's mood suddenly improved. Now he spent days playing with the gifted constructor. Recently, he came up with an unusual entertainment.

Alex builds a tree from his constructor, consisting of nn vertices numbered from 11 to nn , with the root at vertex 11 . Then he writes down each integer from 11 to nn in some order, obtaining a permutation pp . After that, Alex comes up with qq triples of integers l,r,xl, r, x . For each triple, he tries to determine if there is at least one descendant of vertex xx among the vertices pl,pl+1,,prp_l, p_{l+1}, \ldots, p_r .

A vertex uu is a descendant of vertex vv if and only if dist(1,v)+dist(v,u)=dist(1,u)\mathrm{dist}(1, v) + \mathrm{dist}(v, u) = \mathrm{dist}(1, u) , where dist(a,b)\mathrm{dist}(a, b) is the distance between vertices aa and bb . In other words, vertex vv must be on the path from the root to vertex uu .

Alex told Zakhar about this entertainment. Now Alex tells his friend qq triples as described above, hoping that Zakhar can check for the presence of a descendant. Zakhar is very sleepy, so he turned to you for help. Help Zakhar answer all of Alex's questions and finally go to sleep.

输入格式

The first line of the input contains a single integer tt ( 1t1041 \le t \le 10^4 ) — the number of test cases.

The first line of each test case contains two integers n,qn, q ( 1n,q1051 \le n, q \le 10^5 ) — the number of vertices in the tree and the number of questions, respectively.

Each of the next n1n - 1 lines contains two integers uiu_i and viv_i ( 1ui,vin1 \le u_i, v_i \le n ), indicating that there is an edge between vertices uiu_i and viv_i (it is guaranteed that the resulting graph is a tree).

The next line contains nn integers p1,p2,,pnp_1, p_2, \dots, p_n ( 1pin1 \le p_i \le n ) — the permutation pp (it is guaranteed that each integer from 11 to nn appears exactly once).

Then follow qq lines describing Alex's questions. The ii -th line contains three integers l,r,xl, r, x ( 1lrn1 \le l \le r \le n , 1xn1 \le x \le n ), as described in the statement.

It is guaranteed that the sum of nn and the sum of qq over all test cases do not exceed 10510^5 .

输出格式

For each of Alex's questions, print "Yes" (without quotes) if the described descendant exists, otherwise print "No" (without quotes).

You can output the answer in any case (for example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as a positive answer).

输入输出样例

  • 输入#1

    3
    3 5
    1 2
    2 3
    1 2 3
    1 2 2
    1 2 3
    2 3 1
    1 2 3
    2 3 3
    10 10
    2 6
    2 7
    2 4
    1 7
    2 8
    10 6
    8 5
    9 4
    3 4
    10 2 5 9 1 7 6 4 3 8
    8 9 8
    7 8 1
    7 10 6
    4 8 9
    5 5 10
    7 10 1
    9 9 2
    9 10 6
    6 6 2
    10 10 6
    1 1
    1
    1 1 1

    输出#1

    YES
    NO
    YES
    NO
    YES
    
    NO
    YES
    YES
    YES
    NO
    YES
    YES
    NO
    NO
    NO
    
    YES
首页