1079. Total Sales of Supply Chain (25)

#include <iostream>
#include <queue>
#include <vector>

using namespace std;

double p, r, res, amount[100010];
queue<int> q;
vector<int> v[100010];

void bfs()
{
	int qsize = q.size(), cur, vsize, i, next;
	while(qsize--)
	{
		cur = q.front();
		q.pop();

		vsize = v[cur].size();
		if(vsize == 0)
		{
			res += amount[cur] * p;
		}
		else
		{
			for(i = 0; i < vsize; i++)
			{
				next = v[cur][i];
				q.push(next);
			}
		}
	}

	qsize = q.size();
	if(qsize > 0)
	{
		p *= r;
		bfs();
	}
}

int main()
{
	int n;
	scanf("%d%lf%lf", &n, &p, &r);
	r = 1 + r / 100;

	int i, k, j, next;
	for(i = 0; i < n; i++)
	{
		scanf("%d", &k);

		if(k == 0)
		{
			scanf("%lf", &amount[i]);
		}
		else
		{
			for(j = 1; j <= k; j++)
			{
				scanf("%d", &next);
				v[i].push_back(next);
			}
		}
	}

	q.push(0);
	bfs();

	printf("%.1lf\n", res);

	system("pause");
	return 0;
}

 

posted on 2025-11-23 17:17  王景迁  阅读(2)  评论(0)    收藏  举报

导航