1. 程式人生 > >PAT (Advanced Level) Practice 1106 Lowest Price in Supply Chain (25 分)

PAT (Advanced Level) Practice 1106 Lowest Price in Supply Chain (25 分)

#include<cstdio>
#include<vector>
#include<cmath>
using namespace std;

const int N=1e5+5;

vector<int> G[N];
int num,n;
double mxx,p,r;

void dfs(int u,double sum)
{
    int f=0;
    for(int i=0;i<G[u].size();i++)
    {
        int v=G[u][i];
        f=1;dfs(v,sum*(1+
0.01*r)); } if(!f) { if(sum-mxx<-1e-6) mxx=sum,num=1; else if(fabs(sum-mxx)<1e-6) num++; } } int main() { scanf("%d%lf%lf",&n,&p,&r); for(int i=0;i<n;i++) { int x;scanf("%d",&x); for(int j=0;j<x;j++) { int
v;scanf("%d",&v); G[i].push_back(v); } } mxx=1e11; dfs(0,p); printf("%.4lf %d\n",mxx,num); return 0; }