A1079. Total Sales of supply Chain (25)

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. Only the retailers would face the customers. 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 total sales from all the 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 their ID ' s is numbered from 0 to N-1, and the root supplier ' s ID is 0); P, the unit price given by the root supplier; and r, the percentage rate of price increment for each distributor or retailer. Then N lines follow, each describes a distributor or retailer in the following format:

Ki id[1] id[2] ... Id[ki]

Where in the i-th line, Ki was the total number of distributors or retailers who receive products from supplier I, and are T Hen followed by the ID ' s of these distributors or retailers. Kj being 0 means that the j-th member was a retailer, then instead the total amount of the product would be given after Kj. All the numbers in a line is separated by a space.

Output Specification:

For each test case, print in one line the total sales we can expect from all the retailers, accurate up to 1 decimal place . It is guaranteed the number would not be exceed 1010.

Sample Input:

10 1.80 1.003 2 3 51 91 41 70 72 6 11 80 90 40 3

Sample Output:

42.4

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; - structnode{ the     intdata; -vector<int>Child ; - }NODE[MAXN]; -  + voidDFS (intRootintdepth) - { +     if(node[root].child.size () = =0) A     { atAns+=pow (1+r,depth) *Node[root].data; -}Else -     { -          for(intI=0; I<node[root].child.size (); i++) -         { -DFS (node[root].child[i],depth+1); in         } -     } to } + intMain () { -      thescanf"%d%lf%lf",&n,&p,&R); *r=r/ -; $      for(intI=0; i<n;i++)Panax Notoginseng     { -         intm; thescanf"%d",&m); +         if(m==0) A         { thescanf"%d",&node[i].data);  +}Else -         { $          for(intj=0; j<m;j++) $         { -             inttmp; -scanf"%d",&tmp); the Node[i].child.push_back (TMP);  -         }Wuyi         } the     } -DFS (0,0); Wuprintf"%.1f", p*ans); -     return 0; About}

A1079. Total Sales of supply Chain (25)

Related Article

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.