题干:https://pintia.cn/problem-sets/994805342720868352/problems/994805376476626944
题解:做了30分钟,拿了满分
// A1090.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//
#include <bits/stdc++.h>
using namespace std;
#define max 100010
unordered_map<int, vector<int>> gn;
unordered_map<int, bool> visit;
//vector<bool> visit(max, false);
int n; double p, r;
double highest_price = -1;
vector<double> an;
void DFS(int root,double p) {
if (p > highest_price) {
highest_price = p;
}
if (gn[root].size() == 0) {
an.push_back(p);
return;
}
for (int i = 0; i < gn[root].size(); i++) {
if (visit[gn[root][i]] != true) {
visit[gn[root][i]] = true;//debug 不等于true的时候,可以进行遍历,但是在遍历以后要设为true
DFS(gn[root][i],p*(1.0+r));//debug 不是直接输入root,是用它的领接表里面的内容
visit[gn[root][i]] = false;
}
}
}
int main()
{
#ifndef ONLINE_JUDGE
FILE* s1;
freopen_s(&s1, "in.txt", "r", stdin);
#endif // !ONLINE_JUDGE
cin >> n >> p >> r;
r = r / 100.0; //debug r没有除100之前是不能用的,因为有一个百分比的说法
int s;
int root = -1;
for (int i = 0; i < n; i++) {
cin >> s;
if (s != -1) {
gn[s].push_back(i);
}
else {
root = i;
}
}
DFS(root,p);
int match = 0;
for (int i = 0; i < an.size(); i++) {
if (an[i] == highest_price) {
match++;
}
}
printf("%.2f %d\n",highest_price,match);
return 0;
}