#P1332. Degree of Skewness

    ID: 333 传统题 1000ms 256MiB 尝试: 0 已通过: 0 难度: (无) 上传者: 标签>普及/提高-数据结构深度优先搜索树论模拟

Degree of Skewness

Degree of Skewness

题目描述

Given a binary tree, let nLnL​ denotes the number of nodes with only a left child, and nRnR​ the number of nodes with only a right child. The degree of skewness is defined to be Ds=nLnRDs​=nL​−nR​. Your job is to calculate DsDs​ for a given binary tree.

输入格式

Each input file contains one test case. For each case, the first lines gives a positive integer n(103)n (≤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 11 to nn. All the numbers in a line are seperated by a space.

输出格式

Print in a line the degree of skewness in the format:

Ds​ = nL​ - nR​

样例 #1

样例输入 #1

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

样例输出 #1

2 = 3 - 1