1090. Highest Price in Supply Chain (25)

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 (<=105), 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 Si is the index of the supplier for the i-th member. Sroot 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 1010.

Sample Input:

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

Sample Output:

1.85 2
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std; const int maxn=1e5+;
const int INF=1e9;
struct Node
{
int data;
vector<int> child;
}node[maxn]; int max_deep=;
int layer[maxn]={}; void dfs(int s,int &deep)
{
if(node[s].child.size()==)
{
layer[deep]+=;
max_deep=max_deep>deep?max_deep:deep;
return ;
}
for(int i=;i<node[s].child.size();i++)
{
int v=node[s].child[i];
deep+=;
dfs(v,deep);
deep-=;
}
} int main()
{
int n;
double p,r;
cin>>n>>p>>r;
int root;
for(int i=;i<n;i++)
{
int f;
////scanf("%d",&f);
cin>>f;
if(f==-)
{
root=i;
continue;
}
node[f].child.push_back(i); }
int deep=;
dfs(root,deep);
double sum=p;
int tmp=max_deep;
while(tmp>)
{
tmp--;
sum*=(+r/.);
}
printf("%.2lf %d\n",sum,layer[max_deep]);
}

最新文章

  1. SQL Server2014 SP2关键特性
  2. 命令查看DB restore进度
  3. 【转载】Restarting an analysis in ANSYS
  4. iOS学习之代码块(Block)
  5. android firmware 利用UDP socket发送Magic Packet--c语言版本
  6. ListView、PullToRefreshListView滑动加载可见item
  7. jquery 实现邮箱输入自动提示功能:(二)
  8. het smooth 组装高杂合度二倍体基因组前期数据处理
  9. 解决dedev5.7更新出现include\userlogin.class.php on line 21的办法
  10. Python2安装说明
  11. linux编程获取本机网络相关参数
  12. Hyper-V故障转移群集
  13. Android中将Bitmap对象以PNG格式保存在内部存储中
  14. UVA 10404 Bachet&#39;s Game(dp + 博弈?)
  15. intelliJ IDEA创建web工程
  16. 不使用接口的 limit 控制分页的容量
  17. ueditor富文本编辑器跨域上传图片解决办法
  18. Azure系列2.1.4 —— BlobInputStream
  19. Vertica系列: Vertica DB连接负载均衡
  20. Android 常见异常及解决办法

热门文章

  1. import require
  2. 关于manacher
  3. 23-[jQuery]-效果:隐藏,淡出,盒子高度,动画
  4. iOS开发-通过正则表达式进行各种判断银行卡,车牌号,邮箱地址,QQ,身份证,全字母,仅输入字母或数字同时包含大小写字母和数字,仅能输入中文等
  5. Object C学习笔记5-ARC forbids explicit message* 编译错误
  6. UWP Xaml设计器中输入特殊字符
  7. 换新 IP 地址的时候,ORCL前置准备条件
  8. php常用的魔术方法
  9. Java中的Union Types和Intersection Types
  10. 模拟websocket推送消息服务mock工具二