Topic Information
1106. Lowest Price in Supply Chain (25)
Time limit of MS
Memory Limit 65536 KB
Code length limit 16000 B
A supply chain is a network of retailers (retailer), distributors (dealer), and suppliers (supplier) –everyone involved in moving a produc T 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 lowest price a customer 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 (<=10^5), the total number of the "members" in the Suppl Y chain (and hence their ID ' s is numbered from 0 to N-1, and the root supplier ' s ID is 0); P, the price of 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 the j-th member is a retailer. All the numbers in a line is separated by a space.
Output Specification:
For each test case, print in one line the lowest price we can expect from some retailers, accurate up to 4 decimal places, And the number of retailers that sell at the lowest price. There must be one space between the numbers. It is guaranteed, the all the prices would not exceed 10^10.
Sample Input:
10 1.80 1.00
3 2 3 5
1 9
1 4
1 7
0
2 6 1
1 8
0
0
0
Sample Output:
1.8362 2
Thinking of solving problems
Achievements and then search
AC Code
#include <cstdio>#include <vector>#include <cmath>using namespace STD; vector<int>level[100005];intMINLV =999999, Minnum;voidDfsintRootintLV) {if(level[root].size () = =0){if(LV < MINLV) {MINLV = LV; Minnum =1; }Else if(LV = = MINLV) {++minnum; } }Else{ for(inti =0; I < level[root].size (); ++i) {DFS (level[root][i], LV +1); } }}intMain () {intN, T, TN;DoubleP, R;scanf("%D%LF%LF", &n, &p, &r); for(inti =0; I < n; ++i) {scanf("%d", &TN); for(intj =0; J < TN; ++J) {scanf("%d", &t); Level[i].push_back (t); }} DFS (0,0);printf("%.4f%d\n",POW(1.0+ r/ -, MINLV) * p, Minnum);return 0;}
1106. Lowest Price in Supply Chain (25) "Tree + Deep Search"--pat (Advanced level) practise