单选题

#includeusing&nb...

发布于 2022-03-03 14:07:44

#include<bits/stdc++.h>
using namespace std
vector<int>g[15]
int dfs(int x){
    if(g[x].size() == 0){
    return 1
}
int ans = 0
for(int i = 0 i < g[x].size() ++i){
    ans = max(ans, dfs(g[x][i]))
}
    return ans + 1
}
int main(){
    int n, x
    scanf("%d", &n)
    for(int i = 2 i <= n ++i){
        scanf("%d", &x)
        g[x].push_back(i)
    }
    cout << dfs(1) << endl
}
输入为:
10
1 1 2 2 5 5 3 8 6
上述程序的输出为(     )?

登录后免费查看答案
关注者
0
被浏览
17
知识点
面圈网VIP题库

面圈网VIP题库全新上线,海量真题题库资源。 90大类考试,超10万份考试真题开放下载啦

去下载看看