Repovive
  • Dashboard
  • Ranking
  • Submissions
  • Discussion
  1. Contests
  2. Premier Round 4
  3. 9G

My submissions

/
/
/
/

Announcements

My submissions

/
/
/
/

Announcements

Solve
Author

9G. Path XOR Rank

3500 pts·4.7s·512 MB

Constraints

Input

Output

Samples

Input
5
1 1
5
2 3
5 3
1 2
3 5
1 2 4
1 2
2 3
4 7
0 7 7 1
1 2
1 3
3 4
5 12
2 2 5 1 4
1 2
1 3
3 4
3 5
Explanation
Case 1
Case 2
Case 3
Case 4
Case 5
Output
5
6
4
6
3

You are given a tree with nnn vertices. Vertex iii has a value aia_iai​.

For every ordered pair of vertices (u,v)(u,v)(u,v) with 1≤u,v≤n1 \le u,v \le n1≤u,v≤n, write down the xor of all values on the simple path from uuu to vvv.

There are exactly n2n^2n2 written numbers.

Find the kkk-th smallest number among them.

  • 1≤t≤1041 \le t \le 10^41≤t≤104
  • 1≤n≤2×1051 \le n \le 2 \times 10^51≤n≤2×105
  • 1≤k≤n21 \le k \le n^21≤k≤n2
  • 0≤ai<2300 \le a_i < 2^{30}0≤ai​<230
  • The sum of nnn over all test cases is at most 2×1052 \times 10^52×105
  • The given edges form a tree
ttt nka1a2⋯anu1v1u2v2⋮un−1vn−1}×t\left. \begin{array}{l} n \quad k \\ a_1 \quad a_2 \quad \cdots \quad a_n \\ u_1 \quad v_1 \\ u_2 \quad v_2 \\ \vdots \\ u_{n-1} \quad v_{n-1} \end{array} \right\} \times tnka1​a2​⋯an​u1​v1​u2​v2​⋮un−1​vn−1​​⎭⎬⎫​×t
ans}×t\left. \begin{array}{l} ans \end{array} \right\} \times tans​}×t

The written numbers are: (1,1)(1,1)(1,1): path 111, xor 555. After sorting, the first one is 555.

The written numbers are: (1,1)(1,1)(1,1): path 111, xor 555. (1,2)(1,2)(1,2): path 1,21,21,2, xor 5⊕3=65 \oplus 3 = 65⊕3=6. (2,1)(2,1)(2,1): path 2,12,12,1, xor 3⊕5=63 \oplus 5 = 63⊕5=6. (2,2)(2,2)(2,2): path 222, xor 333. After sorting them as 3,5,6,63, 5, 6, 63,5,6,6, the third one is 666.

The sorted written numbers are 1,2,3,3,4,6,6,7,71, 2, 3, 3, 4, 6, 6, 7, 71,2,3,3,4,6,6,7,7. The fifth one is 444.

The sorted written numbers are 0,0,0,1,1,1,6,6,6,6,7,7,7,7,7,70, 0, 0, 1, 1, 1, 6, 6, 6, 6, 7, 7, 7, 7, 7, 70,0,0,1,1,1,6,6,6,6,7,7,7,7,7,7. The seventh one is 666.

The sorted written numbers are 0,0,0,0,1,1,1,1,1,2,2,3,3,4,4,4,4,4,5,5,5,6,6,7,70, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 6, 6, 7, 70,0,0,0,1,1,1,1,1,2,2,3,3,4,4,4,4,4,5,5,5,6,6,7,7. The twelfth one is 333.