1106 Lowest Price in Supply Chai
2018-09-03 本文已影响0人
zjh3029
#include <iostream>
#include <algorithm>
#include <vector>
#include<set>
#include<cmath>
#include<iomanip>
using namespace std;
#define STP system("pause")
vector<vector<int>>v;
int mindepth=9999;
multiset<int>s;
void dfs(int index,int depth)
{
if (v[index].empty())//如果没有下级则代表是零售商
{
//cout << "depth=" << depth << endl;
mindepth = min(mindepth, depth);
s.insert(depth);
return;
}
for (int j = 0; j < v[index].size(); j++)
{
//cout << v[index][j];
++depth;
dfs(v[index][j],depth);//每进去一层则加一,退出一层则减一
depth--;
}
return;
}
int main()
{
int M,N,index;
double P, r;
cin >> M>>P>>r;
for (int i = 0; i < M; i++)
{
cin >> N;
vector<int> vi;
for (int j = 0; j < N; j++)
{
cin >> index;
vi.push_back(index);
}
v.push_back(vi);
}
dfs(0,0);
cout << setiosflags(ios::fixed) << setprecision(4) << P * pow((1.00 + 0.01*r), mindepth) << " ";
cout << s.count(*(s.begin())) << endl;;
//cout<< mindepth << endl;
STP;
return 0;
}