首页 > 其他 > 详细

树的遍历——A1090 Highest Price in Supply Chain(25)(使用vector<Int> temp[maxn]来当作树)

时间:2020-01-26 20:28:43      阅读:87      评论:0      收藏:0      [点我收藏+]

技术分享图片

 

 

#include <bits/stdc++.h>
#include <stdio.h>
#include <stdlib.h>
#include <queue>
using namespace std;
const int maxn = 100010;
vector<int> child[maxn];
double p,r;
int n,maxDepth = 0,num = 0;
void DFS(int index,int depth){
    if(child[index].size() == 0){
        if(depth > maxDepth){
            maxDepth = depth;
            num = 1;
        }else if(depth == maxDepth){
            num++;
        }
        return;
    }
    for(int i =0;i<child[index].size();++i){
        DFS(child[index][i],depth+1);
    }
}
int main(){
    int father,root;
    scanf("%d%lf%lf",&n,&p,&r);
    r /= 100;
    for(int i=0;i<n;++i){
        scanf("%d",&father);
        if(father != -1){
            child[father].push_back(i);
        }else{
            root = i;
        }
    }
    DFS(root,0);
    printf("%.2f %d\n",p * pow(1+r,maxDepth),num);
    system("pause");
    return 0;
}

 

树的遍历——A1090 Highest Price in Supply Chain(25)(使用vector<Int> temp[maxn]来当作树)

原文:https://www.cnblogs.com/JasonPeng1/p/12234711.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!