L2-020 功夫传人

#include <bits/stdc++.h>

using namespace std;

using ll = long long;

const int N = 1e5 + 10;

vector<int> G[N];

int main() {
    int n;
    double h, r;
    
    cin >> n >> h >> r;
    r /= 100.0;
    map<int, int> mul;
    map<int, double> score;
    for (int i = 0; i < n; i++) {
        int k;
        cin >> k;
        if (k == 0) {
            int v;
            cin >> v;
            mul[i] = v;
        }
        else {
            for (int j = 0; j < k; j++) {
                int v;
                cin >> v;
                G[i].push_back(v);
            }
        }
    }
    double res = 0.0;
    if (mul.count(0)) {
        res = h * mul[0];
    } else {
        score[0] = h;
        queue<int> q;
        q.push(0);
        while (q.size()) {
            int u = q.front();
            q.pop();

            double sc = score[u];
            sc = sc * (1.0 - r);
            for (auto& v : G[u]) {
                if (mul.count(v)) {
                    res += sc * mul[v];
                }
                else {
                    q.push(v);
                    score[v] = sc;
                }
            }
        }
    }
    
    cout << (int)res << "\n";

    return 0;
}

posted @ 2022-03-19 15:02  Xxaj5  阅读(23)  评论(0编辑  收藏  举报