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. Only the retailers will face the customers. 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 lowest price a customer 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 (≤10​5​​), the total number of the members in the supply chain (and hence their ID's are numbered from 0 to N−1, and the root supplier's ID is 0); P, the 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:

K​i​​ ID[1] ID[2] ... ID[K​i​​]

where in the i-th line, K​i​​ is the total number of distributors or retailers who receive products from supplier i, and is then followed by the ID's of these distributors or retailers. K​j​​ being 0 means that the j-th member is a retailer. All the numbers in a line are 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 two numbers. It is guaranteed that the all the prices will 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

 #include <stdio.h>
#include <algorithm>
#include <set>
#include <string.h>
#include <vector>
#include <math.h>
#include <queue>
using namespace std;
const int maxn = ;
int n;
double p,r;
vector<int> res[maxn];
int num=,lvl=;
void bfs(int root){
queue<int> q;
q.push(root);
int flag=;
while(!q.empty()){
queue<int> tmp;
while(!q.empty()){
int now = q.front();
q.pop();
if(res[now].empty()){
num++;
flag=;
}
for(int i=;i<res[now].size();i++){
tmp.push(res[now][i]);
}
}
if(flag)break;
while(!tmp.empty()){
q.push(tmp.front());
tmp.pop();
}
lvl++;
}
}
int main(){
scanf("%d %lf %lf",&n,&p,&r);
int i;
for(i=;i<n;i++){
int k;
scanf("%d",&k);
for(int j=;j<k;j++){
int x;
scanf("%d",&x);
res[i].push_back(x);
}
}
bfs();
p=p*pow((+r/),lvl);
//printf("%d",lvl);
printf("%.4f %d",p,num);
}

注意点:bfs遍历要一层一层保存和入队,用正常的一个队列进行bfs会出现不该入队的元素入队,导致结果错误。例如原本第二层会到达终点,但队列里的第二层元素不是第一个元素就到达终点了,而是后面几个,这样第一个元素的子节点也已经入队,此时如果子节点也到了终点就会多算。

PAT A1106 Lowest Price in Supply Chain (25 分)——树的bfs遍历的更多相关文章

  1. 【PAT甲级】1106 Lowest Price in Supply Chain (25分)

    题意:输入一个正整数N(<=1e5),两个小数P和R,分别表示树的结点个数和商品原价以及每下探一层会涨幅的百分比.输出叶子结点深度最小的商品价格和深度最小的叶子结点个数. trick: 测试点1 ...

  2. [建树(非二叉树)] 1106. Lowest Price in Supply Chain (25)

    1106. Lowest Price in Supply Chain (25) A supply chain is a network of retailers(零售商), distributors( ...

  3. 1090. Highest Price in Supply Chain (25) -计层的BFS改进

    题目如下: A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyon ...

  4. PAT甲级——A1106 Lowest Price in Supply Chain

    A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone invo ...

  5. PAT Advanced 1106 Lowest Price in Supply Chain (25) [DFS,BFS,树的遍历]

    题目 A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)– everyone in ...

  6. 1106. Lowest Price in Supply Chain (25)

    A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone invo ...

  7. A1106. Lowest Price in Supply Chain

    A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone invo ...

  8. PAT 1106 Lowest Price in Supply Chain

    A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone invo ...

  9. PAT (Advanced Level) 1106. Lowest Price in Supply Chain (25)

    简单dfs #include<cstdio> #include<cstring> #include<cmath> #include<vector> #i ...

随机推荐

  1. 初学HTML-9

    详情和概要标签:利用summary标签来描述概要信息,利用details标签来描述详情信息. 默认情况下是折叠显示. 格式:<details> <summary>概要信息< ...

  2. JS中使用document.defaultView.getComputedStyle()、currentStyle()方法获取CSS属性值

    在对网页进行调试的过程中,经常会用到js来获取元素的CSS样式,方法有很多很多,现在仅把我经常用的方法总结如: 1. obj.style:这个方法只能JS只能获取写在html标签中的写在style属性 ...

  3. 【读书笔记】iOS-加速计与陀螺仪

    一,数据的“滤波” 直接从加速度计获得的原始数据,往往不能直接使用,而是需要去除一些干扰数据,这个过程称为“滤波”.“滤波”一词来源于无线电技术中对无线电信号的处理过程.事实上从数学角度而言它们是一样 ...

  4. 视觉slam领域经典综述和具体应用场景

    一.经典综述文章 1.  Durrant-Whyte H, Bailey T. Simultaneous localization and mapping: part I[J]. IEEE robot ...

  5. How to deploy kotlin in androidstudio?

    Kotlin is a good language,more playable than Java.So how do we deploy kotlin? First,install the kotl ...

  6. Expo大作战(三十)--expo sdk api之Permissions(权限管理模块),Pedometer(计步器api)

    简要:本系列文章讲会对expo进行全面的介绍,本人从2017年6月份接触expo以来,对expo的研究断断续续,一路走来将近10个月,废话不多说,接下来你看到内容,讲全部来与官网 我猜去全部机翻+个人 ...

  7. 【Java入门提高篇】Day30 Java容器类详解(十二)TreeMap详解

    今天来看看Map家族的另一名大将——TreeMap.前面已经介绍过Map家族的两名大将,分别是HashMap,LinkedHashMap.HashMap可以高效查找和存储元素,LinkedHashMa ...

  8. 故障小记录:yum 安装报错File "/usr/bin/yum", line 30 except KeyboardInterrupt, e:

    发生原因: 由于yum是基于python的,之前安装我python3,当我修改了python命令的指向到python3之后就会发生这样的问题. 解决办法: 由于我当初想到可能以后还需要python2, ...

  9. [201804012]关于hugepages 3.txt

    [201804012]关于hugepages 3.txt --//有一段时间我一直强调安装oracle一定要配置hugepage,因为现在的服务器内存越来越大,如果还使用4K的页面表,如果内存表占用内 ...

  10. 自动化测试基础篇--Selenium Python环境搭建

    学习selenium python需要的工具: 1.浏览器 2.Python 3.Selenium 4.FireBug(Firefox) 5.chromedriver.IEDriverServer.g ...