H. 2023夏-A-3 Rank of Binary Tree

    传统题 400ms 64MiB

2023夏-A-3 Rank of Binary Tree

该比赛已结束,您无法在比赛模式下递交该题目。您可以点击“在题库中打开”以普通模式查看和递交本题。

题目描述

Here we define the rank of a binary tree as n1×n2/n0n_1\times n_2/n_0 where nin_i is the number of nodes of degree ii for i=0,1,2i=0, 1, 2.
For example, given a tree shown by the figure, its rank is 2×3/4=1.52\times 3/4=1.5.

Given the inorder and preorder traversal sequences of a binary tree, you are supposed to calculate its rank.

输入格式

Each input file contains one test case. For each case, the first line contains a positive integer NN (20\le 20), which is the total number of nodes in the tree. Then given in the following 2 lines are the inorder and preorder traversal sequences of the tree, respectively. All the keys in the tree are distinct positive integers in the range of int.

输出格式

For each case, print in a line the way we calculate the rank, and the integer part of the rank. The format is:

n1 * n2 / n0 = rank

样例

9
2 3 1 5 4 7 8 6 9
1 2 3 6 7 4 5 8 9
2 * 3 / 4 = 1

限制

对于所有的测试用例,限制为400 ms, 64 MB

PAT2023夏季重现赛

未参加
状态
已结束
规则
IOI
题目
9
开始于
2025-11-23 18:30
结束于
2025-11-23 22:00
持续时间
3.5 小时
主持人
参赛人数
31