CF396C On Changing Tree
Description
You are given a rooted tree consisting of $ n $ vertices numbered from $ 1 $ to $ n $ . The root of the tree is a vertex number $ 1 $ .
Initially all vertices contain number $ 0 $ . Then come $ q $ queries, each query has one of the two types:
- The format of the query: $ 1 $ $ v $ $ x $ $ k $ . In response to the query, you need to add to the number at vertex $ v $ number $ x $ ; to the numbers at the descendants of vertex $ v $ at distance $ 1 $ , add $ x-k $ ; and so on, to the numbers written in the descendants of vertex $ v $ at distance $ i $ , you need to add $ x-(i·k) $ . The distance between two vertices is the number of edges in the shortest path between these vertices.
- The format of the query: $ 2 $ $ v $ . In reply to the query you should print the number written in vertex $ v $ modulo $ 1000000007 $ $ (10^{9}+7) $ .
Process the queries given in the input.
Input Format
N/A
Output Format
N/A
Explanation/Hint
You can read about a rooted tree here: http://en.wikipedia.org/wiki/Tree\_(graph\_theory).