70% 为啥?
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <set>
#include <vector>
using namespace std;
int a[1010][3];
bool flag[1010];
int dfs(int now) {
if (a[now][0] == 0) return 1;
if (a[now][0] == 1) return dfs(a[now][1]) + 1;
if (a[now][0] == 2) return max(dfs(a[now][1]),
dfs(a[now][2])) + 1;
}
int main() {
int n, start;
while(cin >> n) {
for (int i = 0; i < n; i++) {
a[i][0] = 0;
flag[i] = false;
}
for (int i = 0; i < n - 1; i++) {
int x, y;
cin >> x >> y;
a[x][++a[x][0]] = y;
}
for (int i = 0; i < n; i++) {
for (int j = 1; j <= a[i][0]; j++) {
flag[a[i][j]] = true;
}
}
for (int i = 0; i < n; i++) {
if (!flag[i]) {
start = i;
break;
}
}
//cout << start << endl;
cout << dfs(start) << endl;
}
return 0;
}