QOJ.ac

QOJ

Time Limit: 5 s Memory Limit: 512 MB Total points: 100

#7855. No-Jump Chess

Statistics

Given a tree with $n$ nodes, initially there is a chess piece on each node.

There are $n-2$ operations in total, where each operation involves removing one chess piece from the tree.

After each operation, output the minimum distance between any two distinct chess pieces on the tree and the number of pairs of pieces that achieve this minimum distance. The queries are forced to be online.

Input

The first line contains two integers $n$ and $tp$.

The next $n-1$ lines each contain two integers $u, v$, representing an edge $(u, v)$ in the tree.

The next $n-2$ lines each contain an integer $x'$, representing the removal of a piece at $x = x' \oplus (lastans \times tp)$, where $\oplus$ denotes the bitwise XOR operation. Initially, $lastans = 0$, and subsequently, $lastans$ represents the number of pairs from the previous query.

Output

There are $n-2$ lines, each containing two integers representing the minimum distance and the number of pairs.

Examples

Input 1

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

Output 1

1 2
2 2
4 1

Input 2

10 1
1 2
1 3
3 4
4 5
5 6
3 7
1 8
6 9
9 10
6
2
1
4
8
2
9
11

Output 2

1 7
1 6
1 5
1 2
1 1
2 1
3 2
3 1

Constraints

For $100\%$ of the data, $2 \leq n \leq 5\times10^5$, $1 \le u, v, x \le n$, and all $x$ are distinct.

Test Case $n \leq$ $tp =$ Other Constraints
$1\sim3$ $100$ $0$ None
$4\sim6$ $1000$ $0$ None
$7\sim12$ $2\times10^5$ $0$ None
$13\sim16$ $2\times10^5$ $1$ $u+1=v$
$17\sim20$ $2\times10^5$ $1$ None
$21\sim25$ $5\times10^5$ $1$ None

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
EditorialOpen Official EditorialQingyu- Download

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.