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;
}
标签:Lowest,知识点,cnt,ve,25,int,deep,step,dfs 来源: https://blog.csdn.net/qq_46527915/article/details/121435364