提交时间:2023-08-23 17:07:12

运行 ID: 99758

#include <bits/stdc++.h> using namespace std; int mx; struct shu{ int l, r; }a[10005]; void dfs(int u, int depth){ mx = max(depth,mx); if(a[u].l != 0) dfs(a[u].l, depth + 1); if(a[u].r != 0) dfs(a[u].r, depth + 1); } int main (){ int n; cin >> n; for (int i = 1; i <= n; i++){ cin >> a[i].l >> a[i].r; } dfs(1, 1); cout << mx; return 0; }