1106 Lowest Price in Supply Chain (25 分)【难度: 一般 / 知识点: 树的遍历】

1106 Lowest Price in Supply Chain (25 分)【难度: 一般 / 知识点: 树的遍历】
https://pintia.cn/problem-sets/994805342720868352/problems/994805362341822464

#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
vector<int>ve[N];
int n,cnt,deep=1e9;
double p,r;
void dfs(int u,int fa,int step)
{
    if(ve[u].size()==0)
    {
        if(deep>step) deep=step,cnt=1;
        else if(deep==step) cnt++;
        return;
    }
    for(int i=0;i<ve[u].size();i++)
    {
        if(ve[u][i]==fa) continue;
        dfs(ve[u][i],u,step+1);
    }
}
int main(void)
{
    cin>>n>>p>>r;
    r/=100;
    for(int i=0;i<n;i++)
    {
        int k; cin>>k;
        for(int j=0;j<k;j++) 
        {
            int id; cin>>id;
            ve[i].push_back(id);
        }
    }
    dfs(0,-1,0);
    printf("%.4lf %d",p*pow(1+r,deep),cnt);
    return 0;
}
上一篇:S_P_A_R_K_stream


下一篇:【论文笔记】www18 Pixie: A System for Recommending 3+ Billion Items to 200+ Million Users in Real-Time