Pigtail Virus
Time limit2sMemory limit1024 MB
Given a perfect binary tree of N cities and Q viruses that each add power p to cities within distance d of a source, print every city's total infection level.
- Level
Medium6 of 10
- Topics
- Tree, Prefix sum, Implementation
- Solved
- No attempts yet
Problem
Nana, a stage girl who travels often, discovers the land of Galrae one day. Galrae has cities, and a two-way road connects the -th city () with the -th city. There is a positive integer that satisfies . In other words, the roads of Galrae form a perfect binary tree.
No one in Galrae wears pigtails. Shocked by this, Nana sets aside her stage duties and builds kinds of pigtail viruses.
Each virus has a power and an infectivity . A virus released in city infects every city within distance of , and each of those cities gains . The distance between cities and is the minimum number of roads on a path from to .
The infection level of a city is the sum of the powers of all viruses that infect it after Nana releases every virus. A city can be infected by two or more kinds of viruses.
Print the infection level of each city after all viruses are released.
Input
The first line contains () and (), separated by a space.
Each of the next lines contains , , and : a virus with power () and infectivity () is released in city ().
Output
Print integers, the infection level of each city in order, separated by spaces.