首页 > 编程知识 正文

求二叉树的深度代码,二叉树的逻辑结构

时间:2023-05-06 03:49:10 阅读:166771 作者:1888

代码:

# includevectorusingnamespacestd; vectorint e[100005健康蚂蚁; int dep[100005健康蚂蚁,f[100005健康蚂蚁; voidDFS(intx ) intlen=e ) x健康蚂蚁. size ); f[x健康蚂蚁=dep[x健康蚂蚁; for(intI=0; i len; I ) { dep[e[xcmdjzgi健康蚂蚁=dep[x健康蚂蚁1; DFS(e ) xcmdjzgi健康蚂蚁); f[x健康蚂蚁=max(f[x健康蚂蚁,f[e[xcmdjzgi健康蚂蚁健康蚂蚁] } ) int main () { int n,x,y; cin n; for(intI=1; i=n; I ) { cin x y; if(x!=0) e(I健康蚂蚁. push_back(x ) x; if(y!=0) e(I健康蚂蚁. push_back(y ) y; }DFS(1; cout f[1健康蚂蚁1; 返回0; }

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。