PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#LCA0000096. Pishty và cây phép thuật (Pishty and Tree)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Pishty và cây phép thuật (Pishty and Tree)
Pishty and Tree
Source: CodeChef
Version: Phuoc Hung OJ Extended
Problem Statement
Pishty explores a castle of rooms connected by bidirectional corridors forming a tree. Each corridor has a positive integer magic value .
For every query , consider only corridors on the unique path from to whose magic values are at most . Find the bitwise XOR of these values, or if none qualify. Queries do not modify the tree.
Input
The first line contains , followed by lines . The next line contains the number of queries , followed by query lines .
Output
Print one XOR result for each of the queries, in order.
Subtasks
- Subtask 1 (20 points): ; ; . Đồ thị là cây vô hướng. Additionally, , .
- Subtask 2 (30 points): ; ; . Đồ thị là cây vô hướng. Additionally, , .
- Subtask 3 (50 points): ; ; . Đồ thị là cây vô hướng.
Examples
Input
5
1 2 1
2 3 2
2 4 5
3 5 10
6
5 4 5
5 4 10
5 4 1
1 2 1
4 1 10
1 5 8
Output
7
13
0
1
4
3
Explanation
The path has weights . The answers are for , for , and for . Path yields . Path with yields .