PAT1090. Highest price in supply Chain

Source: Internet
Author: User

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:print in one line the highest price we can expect from some retailers: from some retailers.
2:the number of retailers that sell at the highest. Highest. That means highest depth.
3: sroot for the root supplier are defined to be-1. That means the value corresponding to I is root.
1#include <iostream>2#include <cstdio>3#include <vector>4#include <cmath>5 using namespacestd;6 #defineMAX 1000107 intN;8 Doublep,r,ans=0;9 intMaxdepth=0;Ten intnum=0; One structNode A { -vector<int>Child ; - }node[max]; the voidDFS (intIndexintdepth) - { -     if(node[index].child.size () = =0) -     { +         if(depth>maxdepth) -         { +Maxdepth=depth; Anum=1; at         } -         Else if(depth==maxdepth) -         { -num++; -         } -         return; in     } -      for(intI=0; I<node[index].child.size (); i++) to     { +DFS (node[index].child[i],depth+1); -     } the } *  $ Panax Notoginseng intMainintargcChar*argv[]) - { the     introot=max-1; +scanf"%D%LF%LF",&n,&p,&R); AR/= -; the      for(intI=0; i<n;i++) +     { -         inttem; $scanf"%d",&tem); $         if(tem==-1) -root=i; -         Else the Node[tem].child.push_back (i); -     }WuyiDFS (Root,0); theprintf"%.2LF%d\n", P*pow (1+r,maxdepth), num); -      Wu     return 0; -}
View Code

PAT1090. Highest price in supply Chain

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.