#P7768. 「CGOI-1」收税
「CGOI-1」收税
Background
An easy check-in problem.
Because holding the Ugly Contest cost too much money, ac decided to send Push_Y to collect taxes.
Problem Description
The Ugly Country consists of cities, and city is the capital. These cities are connected by bidirectional roads of length . Starting from city , moving away from the capital (that is, moving to child nodes), all cities within distance at most are the tax-collection range of city .
City needs to pay yuan in income tax. However, since the tax officer Push_Y likes XOR very much, the final tax paid will be the XOR sum of the tax amounts that should be paid by every city in its tax-collection range.
Push_Y will ask you queries. In each query, he asks how many thousand yuan of income tax city will collect when the tax-collection distance is .
Simplified statement:
Given a tree with nodes, rooted at node . The weight of node is . Let be the depth of node , and the root has depth . There are queries. Each query gives two integers , asking for the value of after dividing by .
Here, means $1\operatorname{xor} 2\operatorname{xor}\cdots\operatorname{xor} n$.
Here, means “and”, and means XOR.
Input Format
The first line contains two positive integers , representing the number of cities and the number of queries.
The second line contains positive integers , representing the income tax amount that each city should pay.
The third line contains positive integers. The -th number means that city is connected by a road to city .
Starting from line , there are lines. Each line contains two positive integers , representing one query.
Output Format
For each query, output one line with one real number, representing the amount of tax collected by that city.
Keep three digits after the decimal point.
6 3
604 545 402 378 25 13
1 2 2 3 3
1 2
3 0
2 4
0.149
0.402
0.733
6 3
6 5 4 3 2 1
1 2 2 3 3
1 2
3 0
2 4
0.004
0.004
0.001
Hint
For of the testdata, .
For of the testdata, . Among them, of the testdata are chains.
For of the testdata, , , , .
Translated by ChatGPT 5