A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone involved in moving a product from supplier to customer.

Starting from one root supplier, everyone on the chain buys products from one's supplier in a price P and sell or distribute them in a price that is r% higher than P. It is assumed that each member in the supply chain has exactly one supplier except the root supplier, and there is no supply cycle.

Now given a supply chain, you are supposed to tell the highest price we can expect from some retailers.

Input Specification:

Each input file contains one test case. For each case, The first line contains three positive numbers: N (<=10^5^), the total number of the members in the supply chain (and hence they are numbered from 0 to N-1); P, the price given by the root supplier; and r, the percentage rate of price increment for each distributor or retailer. Then the next line contains N numbers, each number S~i~ is the index of the supplier for the i-th member. S~root~ for the root supplier is defined to be -1. All the numbers in a line are separated by a space.

Output Specification:

For each test case, print in one line the highest price we can expect from some retailers, accurate up to 2 decimal places, and the number of retailers that sell at the highest price. There must be one space between the two numbers. It is guaranteed that the price will not exceed 10^10^.

Sample Input:

9 1.80 1.00
1 5 4 4 -1 4 5 3 6

Sample Output:

1.85 2
#include<cstdio>
#include<cmath>
#include<vector>
using namespace std;
const int maxn = ;
vector<int> child[maxn];
int n,maxDepth = ,num = ;
double p,r; void DFS(int index,int depth){
if(child[index].size() == ){
if(depth > maxDepth){
maxDepth = depth;
num = ;
}else if(depth == maxDepth){
num++;
}
return;
}
for(int i = ; i < child[index].size(); i++){
DFS(child[index][i],depth+);
}
} int main(){
scanf("%d%lf%lf",&n,&p,&r);
int father,root;
r /= ;
for(int i = ; i < n; i++){
scanf("%d",&father);
if(father != -){
child[father].push_back(i);
}
else{
root = i;
}
}
DFS(root,);
printf("%.2f %d\n",p*pow(+r,maxDepth),num);
return ;
}

最新文章

  1. PS技巧:如何优雅的抠公章?
  2. 使用Githua管理代码
  3. Windows Phone App的dump文件实例分析- System.ExecutionEngineException
  4. WIN7下更改TFS连接用户的方法
  5. Android 中获取 debug 测试 SHA1 和 release SHA1 证书指纹数据的方法
  6. POJ2104 K-th Number 划分树 模板题啊
  7. Java 编程的动态性,第 7 部分: 用 BCEL 设计字节码--转载
  8. HTML - Textarea - 空格的问题解决方式
  9. AndroidGradle--瘦身apk(转发)
  10. [Mysql]备份同库中一张表的历史记录 insert into ..select
  11. Java生成名片式的二维码源码分享
  12. Day 1 下午
  13. linux 工具
  14. H5取经之路——添加hover实现特定效果
  15. WIN8 Metro UI 风格下的微软报表开发与设计 Metro UI SSRS - BIWORK
  16. JavaScript substr() 字符串截取函数使用详解
  17. beego 初体验 - orm
  18. jvm(1)类加载(一)(加载过程,双亲加载)
  19. PHP扩展模块redis安装
  20. 20172329 2018-2019《Java软件结构与数据结构》第一周学习总结

热门文章

  1. Core 导出(流和URL两种)
  2. ZeroMQ自查手册
  3. 关于素数表-C++
  4. VBA 字符串-相关函数(6-12)
  5. web项目服务器安装及配置(虚拟机centOS7)
  6. 【转载】 C#使用string.IsNullOrWhiteSpace方法判断字符串是否为非空字符
  7. php生成一维码以及保存-转载
  8. 二叉树&amp;满二叉树与完全二叉树
  9. Android Room 使用案例
  10. go语言实现限流器