Note
- 树的遍历 – BFS
- the number of retailers — 是个数不是序号!!!
- 简单题,注意细节!!!(太菜了orz)
Code
#include<bits/stdc++.h>
using namespace std;
int n,cnt=0,max_level=-1;
double p,r,max=0.0;
struct Node{
vector<int> child;
double price;
int level;
}nod[100005];
void bfs(int root){
queue<int> q;
q.push(root);
nod[root].level=0;
while(!q.empty()){
int data=q.front();
q.pop();
for(int i=0;i<nod[data].child.size();i++){
q.push(nod[data].child[i]);
nod[nod[data].child[i]].level=nod[data].level+1;
}
if(nod[data].level>max_level){
max_level=nod[data].level;
cnt=1;
}
else if(nod[data].level==max_level) cnt++;
}
}
int main(){
#ifndef ONLINE_JUDGE
freopen("data.txt","r",stdin);
#endif
scanf("%d %lf %lf",&n,&p,&r);
r=r/100.0;
int num,root;
for(int i=0;i<n;i++){
scanf("%d",&num);
if(num==-1){
root=i;
nod[i].price=p;
}
else{
nod[num].child.push_back(i);
}
}
bfs(root);
printf("%.2lf %d",p*pow(1+r,max_level),cnt);
return 0;
}