#P3884. [JLOI2009] 二叉树问题
[JLOI2009] 二叉树问题
Description
For the binary tree shown below, its depth, width, and distances between nodes are as follows:
- Depth: .
- Width: .
- The distance between nodes 8 and 6: .
- The distance between nodes 7 and 6: .
Here, the width is the maximum number of nodes on the same level of the binary tree. The distance between nodes and is defined as twice the number of edges directed toward the root plus the number of edges directed toward the leaves, along the shortest directed path from to .

Given a binary tree rooted at node 1, compute its depth, width, and the distance between two specified nodes .
Input Format
The first line contains an integer , the number of nodes in the tree.
The next lines each contain two integers , indicating that there is an edge connecting and in the tree.
The last line contains two integers , asking for the distance between and .
Output Format
Output three lines, each containing one integer, representing the depth, the width, and the distance between and , in this order.
10
1 2
1 3
2 4
2 5
3 6
3 7
5 8
5 9
6 10
8 6
4
4
8
Hint
For all test points, , and the input describes a tree. It is guaranteed that is the parent of .
Translated by ChatGPT 5
京公网安备 11011102002149号