- 数组0下标不使用
- 节点i的左子节点在位置为(2*i);
- 节点i的右子节点在位置为(2*i+1);
- 节点i的父节点在位置为(i/2);
- 根节点被保存到数组下标为1的位置。
第一行是一个正整数n
,表示数组的大小。
接下来一行n个整数,仅包含-1和正整数,如果输入的是-1,则表示该位置是空节点,反之则为节点编号。输入数据保证整个数组中节点编号是从1到树尺寸连续的。
对于每组案例:首先在第一行输出:"The size of the tree is X",X表示树的尺寸,树的尺寸为二叉树中节点的数目。接着在第二行输出:"Node X is the root node of the tree",X表示二叉树的根节点,也就是数组下标1的位置所储存的节点。接下来输出size行,size表示树的尺寸。每行格式为:"The father of node I is X, the left child is Y, and the right child is Z",I、X、Y、Z的含义为:第I个节点的父节点为X,它的左孩子为Y,它的右孩子为Z。
如果该节点是根节点,没有父亲节点,则X为-1。
如果该节点没有左孩子,则Y为-1。
如果该节点没有右孩子,则Z为-1。
The size of the tree is 7 Node 1 is the root node of the tree The father of node 1 is -1, the left child is 2, and the right child is 3 The father of node 2 is 1, the left child is 4, and the right child is 5 The father of node 3 is 1, the left child is 6, and the right child is 7 The father of node 4 is 2, the left child is -1, and the right child is -1 The father of node 5 is 2, the left child is -1, and the right child is -1 The father of node 6 is 3, the left child is -1, and the right child is -1 The father of node 7 is 3, the left child is -1, and the right child is -1
The size of the tree is 4 Node 3 is the root node of the tree The father of node 1 is 2, the left child is -1, and the right child is -1 The father of node 2 is 3, the left child is 1, and the right child is 4 The father of node 3 is -1, the left child is -1, and the right child is 2 The father of node 4 is 2, the left child is -1, and the right child is -1
温馨提示:为了避免PE,或者肉眼不可见的WA造成不必要的罚时,请使用牛客自带的自测调试功能