然后把 $ans$ 提前设为 $1$ 能AC?这数据纯水打造的吧
by zhuruirong @ 2024-07-11 11:15:30
sorry,代码发错了
```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
int n, a[N], lson[N], rson[N], ans;
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;
}
int ans = check(lson[x], rson[y]) & check(rson[x], lson[y]);
}
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;
}
```
by zhuruirong @ 2024-07-11 11:16:41
谢谢大佬
by keep_eating @ 2024-07-11 11:20:10
@[wangchentao2012](/user/1191398) C我代码你什么意思啊
by zhuruirong @ 2024-07-11 11:28:41
所以这道题写 `cout<<3` 可以直接骗 $32$ 分,加上小判断直接 $48$ 分。
by wsr_jason @ 2024-07-11 12:31:41
[骗分](https://www.luogu.com/discuss/96076)48分
by fmx169169169 @ 2024-10-10 22:57:44