1079题目的改版,测试点还是一样,测试点2是只有根节点的情况,特判输出原价格和数量1就可以了。
附本人AC代码:
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
using namespace std;
bool flag[100010], tmp;
int leavel[100010];
vector<vector<int>>V;
int main() {
int N, num, id, root, maxleavle = 100010, numm = 0;
double P, r;
scanf("%d %lf %lf", &N, &P, &r);
V.resize(N);
for (int i = 0; i < N; i++) {
scanf("%d", &num);
for (int j = 0; j < num; j++) {
scanf("%d", &id);
flag[id] = true;
V[i].push_back(id);
}
}
for (int i = 0; i < N; i++) {
if (flag[i] == false) {
root = i;
break;
}
}
if (N == 1) {
printf("%.4f 1", P);
return 0;
}
queue<int>Q;
Q.push(root);
while (Q.size() != 0) {
int t = Q.front();
if (leavel[t] > maxleavle)break;
else if (leavel[t] == maxleavle&&V[t].size()==0)numm++;
Q.pop();
for (int i = 0; i < V[t].size(); i++) {
leavel[V[t][i]] = leavel[t] + 1;
Q.push(V[t][i]);
if (V[V[t][i]].size() == 0&&!tmp) {//保证只修改一次maxleavel值
maxleavle = leavel[t] + 1;
tmp = true;
}
}
}
printf("%.4lf %d", (double)P*pow((double)1 + 0.01*r, maxleavle), numm);
return 0;
}