不是VIP会员,不能显示答案

题目解答

题目:
(YY的树)题目给出m颗非空有根(根节点编号为1)区分左右儿子的二叉树。

将某一棵给出二叉树的叶子节点换成任意一棵二叉树称为一次变换,即给出的二叉树变换到新二叉树。

同一棵二叉树进行多次变换是指在每次变换后得到的新二叉树上继续进行变换。

若任意一棵大小超过1的二叉树都可以由给出的某一棵给出的二叉树通过有限次变换得到,则输出“Almost Complete”,否则输出“No”。

题目第一行首先读入一个数m,表示二叉树的棵数。

接下来进行m次这样的操作。

读入一个数n,接下来n行每行2个数li和ri分别表示这棵二叉树第i个点的左右儿子编号,若没有左儿子,则li=0,若没有右儿子,则ri=0。

#include<bits/stdc++.h>

using namespace std;

const int N=2e6+5;

int n, m, tot;

vector <int> t;

int lc[N], rc[N];

inline bool isleaf(int u) { ___(1)___;}

inline bool solve(vector <int> t) {

if (t.empty()) return false;

for (auto o : t) if (isleaf(o)) return true;

vector<int> t1,t2,t3,t4;

for (auto o : t) {

if(!lc[o]) t2.push_back(rc[o]);

if(!rc[o]) t1.push_back(lc[o]);

if( ___(2)___ ) {

if (isleaf(lc[o])) t3.push_back(rc[o]);

if (isleaf(rc[o])) t4.push_back(lc[o]);

}

}

___(3)___;

}

int main() {

scanf("%d", &m);

for (int i=1; i<=m; ++i) {

int n; scanf("%d" ,&n);___(4)___;

for (int j=1; j<=n; ++j) {

scanf("%d", &lc[tot+j]); if (lc[tot+j]) lc[tot+j] += tot;

scanf("%d", &rc[tot+j]); if (rc[tot+j]) rc[tot+j] += tot;

}

___(5)___;

}

if (solve(t)) printf("Almost Complete\n");

else printf("No\n");

return 0;

}




选择题

1) ⑴处应填( )。

2) ⑵处应填( )。

3) ⑶处应填( )。

4) ⑷处应填( )。

5) ⑸处应填( )。
考点:
分析:
解答:
评论:
老师: