问题:
给一棵点带权(权各不相同,都是正整数)二叉树的中序和后序遍历,找一个叶子使得它到根的路径上的权和最小。如果有多解,该叶子本身的权应尽量小。
输入:
3 2 1 4 5 7 6
3 1 2 5 6 7 4
输出:
1
#include<iostream> //getline(cin, line)
#include<string>
#include<sstream> //stringstream
using namespace std;
// 因为各个结点的权值各不相同且都是正整数,直接用权值作为结点编号
const int maxv = 10000 + 10;
int in_order[maxv], post_order[maxv], lch[maxv], rch[maxv];
int n;
bool read_list(int* a) {
string line;
if (!getline(cin, line)) return false;
stringstream ss(line);
n =