J. 2024春-A-3 Degree of Skewness

    传统题 400ms 64MiB

2024春-A-3 Degree of Skewness

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

题目描述

Given a binary tree, let nLn_L denotes the number of nodes with only a left child, and nRn_R the number of nodes with only a right child. The degree of skewness is defined to be Ds=nLnRD_s = n_L - n_R. Your job is to calculate DsD_s for a given binary tree.

输入格式

Each input file contains one test case. For each case, the first lines gives a positive integer nn (103\le 10^3) which is the number of nodes in the binary tree. The next two lines contain the post-order and in-order traversal sequences of the tree, respectively. The keys are integers from 1 to nn. All the numbers in a line are seperated by a space.

输出格式

Print in a line the degree of skewness in the format: DsD_s = nLn_L - nRn_R

样例

7
1 2 7 5 4 3 6
1 2 3 4 7 5 6
2 = 3 - 1

限制

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

PAT2024春季重现赛

未参加
状态
已结束
规则
IOI
题目
11
开始于
2025-8-17 14:00
结束于
2025-8-17 17:30
持续时间
3.5 小时
主持人
参赛人数
46