CF1902F.Trees and XOR Queries Again
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given a tree consisting of n vertices. There is an integer written on each vertex; the i -th vertex has integer ai written on it.
You have to process q queries. The i -th query consists of three integers xi , yi and ki . For this query, you have to answer if it is possible to choose a set of vertices v1,v2,…,vm (possibly empty) such that:
- every vertex vj is on the simple path between xi and yi (endpoints can be used as well);
- av1⊕av2⊕⋯⊕avm=ki , where ⊕ denotes the bitwise XOR operator.
输入格式
The first line contains one integer n ( 2≤n≤2⋅105 ).
The second line contains n integers a1,a2,…,an ( 0≤ai≤220−1 ).
Then n−1 lines follow. Each of them contains two integers u and v ( 1≤u,v≤n ; u=v ) denoting an edge of the tree.
The next line contains one integer q ( 1≤q≤2⋅105 ) — the number of queries.
Then q lines follow. The i -th of them contains three integers xi , yi and ki ( 1≤xi,yi≤n ; 0≤ki≤220−1 ).
输出格式
For each query, print YES if it is possible to form a set of vertices meeting the constraints. Otherwise, print NO.
You can print each letter in any case.
输入输出样例
输入#1
4 0 1 2 10 2 1 3 2 4 2 8 3 3 0 3 4 1 3 4 7 1 3 1 1 3 2 1 3 10 1 4 10 1 4 11
输出#1
YES YES NO YES YES NO YES YES