1106 Lowest Price in Supply Chain (25分) PAT

 

#include<cstdio>
#include<vector>
#include<iostream>
#include<queue>
#include<cmath>
#define maxn 100100
#define inf 1000000000

using namespace std;

struct node {
    int d, l;   // index, level
    node(int _d, int _l) : d(_d), l(_l) {}
};

vector<int> child[maxn];
int parents[maxn];

int findroot(int a) {
    int t = a;
    while(parents[t] != inf) {
        t = parents[t];
    }
    return t;
}

int nearest(int &n) {  // return level
    int level = -1, num = 0;
    queue<node> q;
    q.push(node(0, 0));
    while (!q.empty()) {
        node temp = q.front();
        int t = temp.d;
        q.pop();
        if (level != -1 && temp.l != level) break;
        else if (level == -1) {
            if (child[t].size() == 0) {
                level = temp.l;
                num = 1;
            }
            else {
                for (int i = 0; i < child[t].size(); i++) {
                    q.push(node(child[t][i], temp.l + 1));
                }
            }
        }
        else if (temp.l == level && child[t].size() == 0) {
            num++;
        }
    }
    n = num;
    return level;
}

int main() {
    int N;
    double P, R;
    scanf("%d %lf %lf", &N, &P, &R);
    for (int i = 0; i < N; i++) {
        parents[i] = inf;
    }
    int childnum, a;
    for (int i = 0; i < N; i++) {
        scanf("%d", &childnum);
        while(childnum--) {
            scanf("%d", &a);
            child[i].push_back(a);
            parents[a] = i;
        }
    }
    int num = 0;
    int level = nearest(num);
    printf("%.4f %d\n", P * pow(1 + R * 0.01, level), num);


    return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值