A16289 | Trees and XOR Queries Again
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
You are given a tree consisting of $n$ vertices. There is an integer written on each vertex; the $i$ -th vertex has integer $a_i$ written on it.
You have to process $q$ queries. The $i$ -th query consists of three integers $x_i$ , $y_i$ and $k_i$ . For this query, you have to answer if it is possible to choose a set of vertices $v_1, v_2, \dots, v_m$ (possibly empty) such that:
- every vertex $v_j$ is on the simple path between $x_i$ and $y_i$ (endpoints can be used as well);
- $a_{v_1} \oplus a_{v_2} \oplus \dots \oplus a_{v_m} = k_i$ , where $\oplus$ denotes the bitwise XOR operator.
You have to process $q$ queries. The $i$ -th query consists of three integers $x_i$ , $y_i$ and $k_i$ . For this query, you have to answer if it is possible to choose a set of vertices $v_1, v_2, \dots, v_m$ (possibly empty) such that:
- every vertex $v_j$ is on the simple path between $x_i$ and $y_i$ (endpoints can be used as well);
- $a_{v_1} \oplus a_{v_2} \oplus \dots \oplus a_{v_m} = k_i$ , where $\oplus$ denotes the bitwise XOR operator.
输入格式
The first line contains one integer $n$ ( $2 \le n \le 2 \cdot 10^5$ ).
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ( $0 \le a_i \le 2^{20} - 1$ ).
Then $n-1$ lines follow. Each of them contains two integers $u$ and $v$ ( $1 \le u, v \le n$ ; $u \ne v$ ) denoting an edge of the tree.
The next line contains one integer $q$ ( $1 \le q \le 2 \cdot 10^5$ ) — the number of queries.
Then $q$ lines follow. The $i$ -th of them contains three integers $x_i$ , $y_i$ and $k_i$ ( $1 \le x_i, y_i \le n$ ; $0 \le k_i \le 2^{20} - 1$ ).
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ( $0 \le a_i \le 2^{20} - 1$ ).
Then $n-1$ lines follow. Each of them contains two integers $u$ and $v$ ( $1 \le u, v \le n$ ; $u \ne v$ ) denoting an edge of the tree.
The next line contains one integer $q$ ( $1 \le q \le 2 \cdot 10^5$ ) — the number of queries.
Then $q$ lines follow. The $i$ -th of them contains three integers $x_i$ , $y_i$ and $k_i$ ( $1 \le x_i, y_i \le n$ ; $0 \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.
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
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted