report VI VI EN
Register | Login
  • HOME
  • PROBLEMSET
  • ROADMAP
  • COMPETITION
  • TOPIC
  • RANKING
  • GUIDE
  • MASHUP
  • ABOUT
  • CONTACT
  • Problem
  • Submit
  • Results
Tree query - FlandreOJ: Flandre Online Judge

Tree query

Time limit: 1000 ms
Memory limit: 256 MB
Given a tree with $n$ vertices. Each vertex initially has a weight of $0$. You are given $q$ queries, each of the following types: - `1 u d`: increase the weight of every vertex adjacent to vertex $u$ by $d$. - `2 u`: report the current weight of vertex $u$. ### Input - The first line contains two integers $n$ and $q$. - The next $n - 1$ lines each contain two integers $u$ and $v$, indicating an edge between vertex $u$ and vertex $v$. ### Output - For each query of type `2`, print the result (the weight of the vertex $u`). ### Constraints - $1 \le n,q \le 10^5$. - $1 \le u, v \le n$. - $1 \le d \le 10^9$. ### Example Input: ``` 3 2 1 2 1 3 1 1 1 2 3 ``` Output: ``` 1 ```
Square root decomposition
Frequency
Tree query
Inversions query
Nearest vertex
Dominating color
String occurences 3
Inversions query 2
Pair
Sparse update
Tree
Range query
String concatenation
Subarray distance
Chameleon
Knapsack
Bit counting
Subsequence queries
Sub-subsequence
Delete numbers
Mode
Marisa is happy
Inversions query 3
Upperbound
23 path
Yet another square root decomposition problem
Marisa plays poker
Wonderful world
Topic
Tree
Rating 1500
Solution (3) Solution