CF1902F.Trees and XOR Queries Again

提高+/省选-

通过率:0%

时间限制:6.50s

内存限制:512MB

AC君温馨提醒

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

题目描述

You are given a tree consisting of nn vertices. There is an integer written on each vertex; the ii-th vertex has integer aia_i written on it.

You have to process qq queries. The ii-th query consists of three integers xix_i, yiy_i and kik_i. For this query, you have to answer if it is possible to choose a set of vertices v1,v2,…,vmv_1, v_2, \dots, v_m (possibly empty) such that:

  • every vertex vjv_j is on the simple path between xix_i and yiy_i (endpoints can be used as well);
  • av1⊕av2⊕⋯⊕avm=kia_{v_1} \oplus a_{v_2} \oplus \dots \oplus a_{v_m} = k_i, where ⊕\oplus denotes the bitwise XOR operator.

给你一棵包含 nn 个顶点的树。每个顶点上写有一个整数;第 ii 个顶点上写的整数为 aia_i。

你需要处理 qq 个查询。第 ii 个查询包含三个整数 xix_i、yiy_i 和 kik_i。对于该查询,你需要判断:是否存在一个顶点集合 v1,v2,…,vmv_1, v_2, \dots, v_m(该集合可以为空),使得:

  • 每个顶点 vjv_j 都位于 xix_i 与 yiy_i 之间的简单路径上(端点也可被选用);
  • av1⊕av2⊕⋯⊕avm=kia_{v_1} \oplus a_{v_2} \oplus \dots \oplus a_{v_m} = k_i,其中 ⊕\oplus 表示按位异或运算符。

输入格式

The first line contains one integer nn (2≤n≤2⋅1052 \le n \le 2 \cdot 10^5).

The second line contains nn integers a1,a2,…,ana_1, a_2, \dots, a_n (0≤ai≤220−10 \le a_i \le 2^{20} - 1).

Then n−1n-1 lines follow. Each of them contains two integers uu and vv (1≤u,v≤n1 \le u, v \le n; u≠vu \ne v) denoting an edge of the tree.

The next line contains one integer qq (1≤q≤2⋅1051 \le q \le 2 \cdot 10^5) — the number of queries.

Then qq lines follow. The ii-th of them contains three integers xix_i, yiy_i and kik_i (1≤xi,yi≤n1 \le x_i, y_i \le n; 0≤ki≤220−10 \le k_i \le 2^{20} - 1).

第一行包含一个整数 nn(2≤n≤2⋅1052 \le n \le 2 \cdot 10^5)。

第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \dots, a_n(0≤ai≤220−10 \le a_i \le 2^{20} - 1)。

接下来是 n−1n-1 行,每行包含两个整数 uu 和 vv(1≤u,v≤n1 \le u, v \le n;u≠vu \ne v),表示树中的一条边。

下一行包含一个整数 qq(1≤q≤2⋅1051 \le q \le 2 \cdot 10^5),表示查询的数量。

接下来是 qq 行,其中第 ii 行包含三个整数 xix_i、yiy_i 和 kik_i(1≤xi,yi≤n1 \le x_i, y_i \le n;0≤ki≤220−10 \le k_i \le 2^{20} - 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.

对于每个查询,如果能够构造出一组满足约束条件的顶点,则输出 YES;否则输出 NO。

您可以以任意大小写形式输出每个字母。

输入输出样例

  • 输入#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

输入解题思路,AI测评打分。不知道怎么写?

首页