Back to Cosmos

Problem Link

code/online_challenges/src/codechef/BACREP/README.md

latest1.1 KB
Original Source

Problem Link

BACREP

Description

Chef has a rooted tree with N vertices (numbered 1 through N); vertex 1 is the root of the tree. Initially, there are some bacteria in its vertices. Let's denote the number of sons of vertex v by sv; a leaf is a vertex without sons. During each second, the following events happen:

For each non-leaf vertex v, if there are x bacteria in this vertex at the start of this second, they divide into sv⋅x bacteria. At the end of this second, x of these bacteria instantly move to each of its sons (none of them stay in vertex v). The original x bacteria do not exist any more. Zero or more bacteria appear in one vertex. These bacteria do not divide or move at this second. Initially, we are at the start of second 0. You should process Q queries ― one query during each of the seconds 0 through Q−1. There are two types of queries:

  • v k: During this second, k bacteria appear in vertex v. ? v: Find the number of bacteria in vertex v at the end of this second ― after the divided bacteria have moved.