#include<stdio.h>#include<vector>Usingnamespace Std;Constint max=100010;int depest=0,times=0;vector<Int> Child[max];child[father [Child] two-dimensional array representation tree structurevoid DFS (int root,int depth) {if (child[root].size () = =0)The leaf node begins to judge the depth {if (depth>depest) {depest=depth; times=1; }Elseif (depth==depest)The same as the deepest depth, the number of times plus 1 ++times;Return }Forint i=0; I<child[root].size (); ++i) DFS (child[root][i],depth+1);}int main () {int root=-1,n;Double p,r; scanf"%d%lf%lf", &n,&p,&r); R/=100;into percentagesForint i=0; i<n; ++i) {int father ; scanf ( "%d",& Father); if (father==-1) root=i; else {child[father].push_back (i);}} DFS (root,0); double ans=p; //calculates the highest price for (int i= 0; i<depest; ++i) ans=ans* (1+r); printf ( "%.2f%d\n" Ans,times "; return 0;}
pat:1090. Highest price in supply Chain (+) AC