代码:
# 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; }