UVA 12186(p282)----Another Crisis

#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
using namespace std;
const int maxn=1e5+50;
int n,t;
vector<int> son[maxn];
int solve(int u)
{
    if(son[u].empty()) return 1;
    int num=son[u].size();
    int c=(num*t-1)/100+1;
    vector<int> d;
    for(int i=0; i<num; i++)
        d.push_back(solve(son[u][i]));
    sort(d.begin(),d.end());
    int ans=0;
    for(int i=0; i<c; i++)
        ans+=d[i];
    return ans;
}
int main()
{
    while(scanf("%d%d",&n,&t)==2&&n)
    {
        for(int i=0;i<=n;i++) son[i].clear();
        for(int i=1; i<=n; i++)
        {
            int x;
            scanf("%d",&x);
            son[x].push_back(i);
        }
        printf("%d\n",solve(0));
    }
    return 0;
}

你可能感兴趣的:(UVA 12186(p282)----Another Crisis)