有没有人能告诉我,我的代码到底错在哪
2026-07-16 13:33:49
发布于:浙江
43阅读
0回复
0点赞
#include<bits/stdc++.h>
using namespace std;
struct node{
int l,r;
};
int n;
node a[100010];
int cnt = 0;
int vis[100010];
void dfs( int idx ){
if ( a[idx].l == 0 && a[idx].r == 0 ){
cnt++;
return ;
}
if ( a[idx].l != 0 && vis[idx] != 1 ){
vis[idx] = 1;
dfs(a[idx].l);
vis[idx] = 0;
}
if ( a[idx].r != 0 && vis[idx] != 1 ){
vis[idx] = 1;
dfs(a[idx].r);
vis[idx] = 0;
}
}
int main(){
cin >> n;
for ( int i = 1; i <= n; i++ ){
cin >> a[i].l >> a[i].r;
}
vis[1] = 1;
dfs(1);
cout << cnt;
return 0;
}
这里空空如也





有帮助,赞一个