这数据也太水了吧
查看原帖
这数据也太水了吧
764442
__zhuruirong__楼主2024/7/11 11:14

我没有return也能拿96?过分了昂!

#include <bits/stdc++.h>
using namespace std;

const int N = 1e6 + 10;
int n, a[N], lson[N], rson[N], ans = 1;

bool check(int x, int y) {
	if(x == -1 and y == -1) {
		return true;
	}
	if(x == -1 or y == -1 or a[x] != a[y]) {
		return false;
	}
	return check(lson[x], rson[y]) & check(rson[x], lson[y]); // 没return能拿96
}

int cnt(int x) {
	if(x == -1) {
		return 0;
	}
	int ans = 1;
	ans += cnt(lson[x]) + cnt(rson[x]);
	return ans;
}

int main() {
	
	cin >> n;
	for(int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	for(int i = 1; i <= n; i++) {
		cin >> lson[i] >> rson[i];
	}
	for(int i = 1; i <= n; i++) {
		if(lson[i] != -1 and rson[i] != -1 and a[lson[i]] == a[rson[i]] and check(lson[i], rson[i])) {
			ans = max(ans, cnt(i));
		}
	}
	cout << ans << "\n";
	
	return 0;
}
2024/7/11 11:14
加载中...