求助案例过了,测试全wa
查看原帖
求助案例过了,测试全wa
1212171
TaoQunHUAN楼主2024/1/19 10:29
#include<bits/stdc++.h>
using namespace std;
typedef struct {
	int l, r;
}TR;

typedef TR* qtr;
TR tree[1000050];


int  dfs(TR q[100005],int t) {
	int trl; int trr;
	if (q[t].l == 0 && q[t].r == 0) {
		return 1;
	}if (q[t].l != 0) {
		trl=dfs(q, q[t].l);
	}
	else if (q[t].r != 0) {
		trr=dfs(q, q[t].r);
	}
	return max(trl, trr)+1;
}

int main() {
	int t;
	cin >> t;
	for (int i = 1; i <= t; i++) {
		cin >> tree[i].l >> tree[i].r;
	}
	int ans = dfs(tree, 1);
	cout << ans << endl;
	return 0;
}
2024/1/19 10:29
加载中...