CF1055F.Tree and XOR

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given a connected undirected graph without cycles (that is, a tree) of nn vertices, moreover, there is a non-negative integer written on every edge.

Consider all pairs of vertices (v,u)(v, u) (that is, there are exactly n2n^2 such pairs) and for each pair calculate the bitwise exclusive or (xor) of all integers on edges of the simple path between vv and uu . If the path consists of one vertex only, then xor of all integers on edges of this path is equal to 00 .

Suppose we sorted the resulting n2n^2 values in non-decreasing order. You need to find the kk -th of them.

The definition of xor is as follows.

Given two integers xx and yy , consider their binary representations (possibly with leading zeros): xkx2x1x0x_k \dots x_2 x_1 x_0 and yky2y1y0y_k \dots y_2 y_1 y_0 (where kk is any number so that all bits of xx and yy can be represented). Here, xix_i is the ii -th bit of the number xx and yiy_i is the ii -th bit of the number yy . Let r=xyr = x \oplus y be the result of the xor operation of xx and yy . Then rr is defined as rkr2r1r0r_k \dots r_2 r_1 r_0 where:

$$ r_i = \left\{ \begin{aligned} 1, ~ \text{if} ~ x_i \ne y_i \\ 0, ~ \text{if} ~ x_i = y_i \end{aligned} \right. $$

输入格式

The first line contains two integers nn and kk ( 2n1062 \le n \le 10^6 , 1kn21 \le k \le n^2 ) — the number of vertices in the tree and the number of path in the list with non-decreasing order.

Each of the following n1n - 1 lines contains two integers pip_i and wiw_i ( 1pii1 \le p_i \le i , 0wi<2620 \le w_i < 2^{62} ) — the ancestor of vertex i+1i + 1 and the weight of the corresponding edge.

输出格式

Print one integer: kk -th smallest xor of a path in the tree.

输入输出样例

  • 输入#1

    2 1
    1 3
    

    输出#1

    0
    
  • 输入#2

    3 6
    1 2
    1 3
    

    输出#2

    2
    

说明/提示

The tree in the second sample test looks like this:

For such a tree in total 99 paths exist:

  1. 111 \to 1 of value 00
  2. 222 \to 2 of value 00
  3. 333 \to 3 of value 00
  4. 232 \to 3 (goes through 11 ) of value 1=231 = 2 \oplus 3
  5. 323 \to 2 (goes through 11 ) of value 1=231 = 2 \oplus 3
  6. 121 \to 2 of value 22
  7. 212 \to 1 of value 22
  8. 131 \to 3 of value 33
  9. 313 \to 1 of value 33
首页