2022.1.28 练习 PAT甲 1106 Lowest Price in Supply Chain(原题链接)
题解如下:
#include <bits/stdc++.h>
using namespace std;
const int MAX_SIZE=100010;
const int INF=1e8;
int n;
double p,r;
vector<int> child[MAX_SIZE];
int min_high=INF,num=0;
void DFS(int index,int high)
{
if(child[index].size()==0)
{
if(high<min_high)
{
min_high=high;
num=1;
}
else if(high==min_high)
{
num++;
}
return;
}
for(unsigned int i=0;i<child[index].size();i++)
{
DFS(child[index][i],high+1);
}
}
int main()
{
std::ios::sync_with_stdio(false);
cin>>n>>p>>r;
r=r/100;
for(int i=0;i<n;i++)
{
int k;
cin>>k;
for(int j=0;j<k;j++)
{
int tmp;
cin>>tmp;
child[i].push_back(tmp);
}
}
DFS(0,0);
cout<<setiosflags(ios::fixed)<<setprecision(4)<<p*pow(1+r,min_high)<<" "<<num;
return 0;
}