luogu#P16610. [Algo Beat 008 & WWOI R3] 银河战区
[Algo Beat 008 & WWOI R3] 银河战区
Problem Description
How wonderful! The starting point and the destination cannot be decided, and the game ends halfway. The light of the end shines upon the earth, and students in the school begin to go to the cafeteria to buy hamburgers.
You have hamburgers, where each hamburger has a deliciousness value . You can place these hamburgers arbitrarily on the nodes of a tree, such that each node contains exactly one hamburger. The hamburgers at school are so delicious, so we define the total deliciousness as follows: for every chain on the tree leading to the root node , calculate the XOR sum of the deliciousness values of the hamburgers on that chain. The total deliciousness is the bitwise AND sum of all these XOR results.
What is the maximum total deliciousness you can obtain after placing the hamburgers on the tree in an optimal way?
I suddenly... really want... to eat... a hamburger...
Original Formal Problem Statement:
There is a tree with nodes, numbered from to , with the root node being ; and a sequence of length .
You can arbitrarily rearrange the sequence , and then sequentially assign the node weight of node on the tree to be , in order to maximize the value of this tree.
We define as the XOR sum of the node weights (including the node itself) on the simple path from node to the root of the tree. Then, the value of the tree is defined as: . That is, the bitwise AND sum of for nodes to .
Input Format
The first line contains a positive integer .
The next line contains positive integers representing the sequence .
The following lines each contain two integers and , indicating that there is an edge between node and node . It is guaranteed that the graph is a tree.
Output Format
Output a single non-negative integer on one line, representing the maximum value of the tree.
5
2 4 4 4 4
1 2
2 3
3 4
4 5
2
Hint
This problem uses bundled testing.
For all test data, the following conditions apply:
- .
- .
| Subtask Number | Special Properties | Score | |
|---|---|---|---|
| None | |||
| ^ | |||
| Data is randomly generated, and | |||
| None |
Translated by Qwen 3.6