提交时间:2023-08-23 16:39:43

运行 ID: 99737

#include <iostream> using namespace std; struct tree { int node,left,right; } lst[114514]; int deep = 0; void dfs(int d,int index) { deep = max(deep,d); if(lst[index].left != 0) { dfs(d+1,lst[index].left); } if(lst[index].right != 0) { dfs(d+1,lst[index].right); } } int main() { int num; cin >> num; for(int i = 1;i <= num;i++) { cin >> lst[i].left >> lst[i].right; lst[i].node = i; } dfs(1,1); cout << deep; }