zoukankan      html  css  js  c++  java
  • 【codevs1501】二叉树最大宽度和高度

    problem

    solution

    codes

    #include<iostream>
    #include<algorithm>
    using namespace std;
    const int maxn = 110;
    int tree[maxn][2], higt, weigt[maxn], ww;
    void dfs(int now, int dep){
        higt = max(higt,dep);
        ww = max(ww, weigt[dep]);
        if(tree[now][0]){ dfs(tree[now][0], dep+1); weigt[dep+1]++; }
        if(tree[now][1]){ dfs(tree[now][1], dep+1); weigt[dep+1]++; }
    }
    int main(){
        int n;  cin>>n;
        for(int i = 1; i <= n; i++)
            cin>>tree[i][0]>>tree[i][1];
        dfs(1, 1);
        cout<<ww+1<<" "<<higt<<"
    ";
        return 0;
    }
  • 相关阅读:
    面试题练习
    小作业7
    小作业6,7
    小作业
    坦克大战
    面试题
    20181213作业
    20181212作业
    20181211作业
    第三周周末作业
  • 原文地址:https://www.cnblogs.com/gwj1314/p/9444706.html
Copyright © 2011-2022 走看看