#ds704. 树上LCA3

树上LCA3

Tree LCA 3

Problem Description

You are given a tree rooted at node 11.

You must answer mm queries. In each query you are given two distinct numbers x,yx, y (x≠yx \neq y), and you must output the lowest common ancestor (LCA) of xx and yy.

Input Format

The first line contains five integers n,m,A,B,Cn, m, A, B, C (0≤A,B,C≤232−10 \leq A, B, C \leq 2^{32} - 1).

The next n−1n - 1 lines each contain two integers x,yx, y (x≠yx \neq y), denoting an edge between xx and yy.

To avoid excessively large input, the queries are generated by the following code:

unsigned int A, B, C;
inline unsigned int rng61() {
    A ^= A << 16;
    A ^= A >> 5;
    A ^= A << 1;
    unsigned int t = A;
    A = B;
    B = C;
    C ^= t ^ A;
    return C;
}
int main(){
    scanf("%d%d%u%u%u", &n, &m, &A, &B, &C);
    // input the tree edges
    for (int i = 1; i <= m; i++) {
        unsigned int u = rng61() % n + 1, v = rng61() % n + 1;
        ans[i] = LCA(u, v);
    }
}

(That is, you do not read the queries explicitly; they are produced internally by this generator.)

Output Format

Suppose the answer to the ii-th query is ansians_i. Output the XOR sum of ansi×ians_i \times i over all queries, i.e. $ans_1 \times 1 \oplus ans_2 \times 2 \oplus \dots \oplus ans_m \times m$.

Sample Input

5 5 1 2 3
1 2
1 3
3 4
3 5

Sample Output

9

Constraints

  • 1≤n≤5×1051 \leq n \leq 5 \times 10^5
  • 1≤x,y≤n, x≠y1 \leq x, y \leq n,\ x \neq y
  • m≤107m \leq 10^7