1090 Highest Price in Supply Chain 发表于 2020-05-31 重点在于理解这一句:each number Si is the index of the supplier for the i-th member.Si是第i个节点的父节点编号。 123456789101112131415161718192021222324252627282930313233343536373839#include <bits/stdc++.h>using namespace std;int n, maxdepth = 0, maxnum = 0, root, temp;double p, r;vector<int> v[100010];void DFS(int root, int depth) { if (v[root].size() == 0) { if (maxdepth == depth) { maxnum++; } if (maxdepth < depth) { maxdepth = depth; maxnum = 1; } return; // 最好加上 } for (int i = 0; i < v[root].size(); i++) { DFS(v[root][i], depth + 1); }}int main() { scanf("%d %lf %lf", &n, &p, &r); for (int i = 0; i < n; i++) { scanf("%d", &temp); if (temp == -1) { root = i; } else { v[temp].push_back(i); } } DFS(root, 0); printf("%.2f %d", p * pow(1 + r / 100, maxdepth), maxnum); return 0;}