A supply chain is a network of retailers (retailer), distributors (dealer), and suppliers (supplier)--everyone involved in moving a produ CT 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 Distribu Te them in a price, is r% higher than P. It is assumed this member in the supply chain have exactly one supplier except the root supplier, and there is no supp Ly cycle.
Now given a supply chain and you is supposed to tell the highest price we can expect from some retailers.
Input Specification:
Each input file contains the 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 is numbered from 0 to N-1); P, the price of 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 and each number Si are the index of the supplier for the i-th member. Sroot for the root supplier are defined to be-1. All the numbers in a line is separated by a space.
Output Specification:
For all test case, print on 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 numbers. It is guaranteed, the price would not exceed 1010.
Sample Input:
9 1.80 1.001 5 4 4-1 4 5 3 6
Sample Output:
1.85 2
1#include <stdio.h>2#include <stdlib.h>3#include <iostream>4#include <string.h>5#include <math.h>6#include <algorithm>7#include <string>8#include <stack>9#include <queue>Ten using namespacestd; One Const intmaxn=100010; A intN; - Doubler,p,ans=0; - thevector<int>CHILD[MAXN]; - - //find the maximum depth - intmaxdep=0, anscount=0; + voidDasointRootintdepth) - { + if(child[root].size () = =0) A { at if(depth>MAXDEP) { -maxdep=depth; -Anscount=1; -}Else if(depth==MAXDEP) - { -anscount++; in}Else{ - } to } + for(intI=0; I<child[root].size (); i++) - { theDFS (child[root][i],depth+1); * } $ }Panax Notoginseng intMain () { - thescanf"%d%lf%lf",&n,&p,&R); +r=r/ -; A intRoot; the for(intI=0; i<n;i++) + { - inttmp; $scanf"%d",&tmp); $ if(tmp==-1) - { -root=i; the}Else - {Wuyi Child[tmp].push_back (i); the } - Wu } -DFS (Root,0); Aboutprintf"%.2f%d", P*pow (1+r,maxdep), anscount); $ return 0; -}
A1090. Highest price in supply Chain (25)