| TheForces Round #30 (Good-Forces) |
|---|
| Finished |
Yugandhar gave a weighted tree initially containing $$$n$$$ nodes to Naveen and Pavan Kalyan in 2023. Almost a year has completed, so he came up with $$$3$$$ types of queries to test their knowledge on trees.
Before asking about queries, Yugandhar came up with an infinite integer array $$$A$$$ defined as $$$(A_0 = 1, A_{n} = A_{n-1}+4)$$$ and an infinite binary array $$$B$$$ defined as $$$(B_0 = 0, B_{2n} = B_{n}, B_{2n+1} = 1-B_{n})$$$. And also he gave one empty array to Naveen and one empty array to Pavan Kalyan and called them as Naveen's array and Pavan kalyan's array respectively.
Later he splits each element of $$$A_i (i \ge 0)$$$ to Naveen's array and Pavan Kalyan's array in the following way:
After splitting, he will ask the following type of queries to both:
Note that the given tree is guaranteed that there is atmost $$$1$$$ edge between two nodes.
Unfortunately, both Naveen and Pavan Kalyan didn't learn much about trees, so please help them by telling answers to the $$$2^{nd}$$$ and $$$3^{rd}$$$ type queries.
The first line of each test contains two integers $$$n,q$$$ $$$(1 \le n,q \le 10^6)$$$ — initial number of nodes in the tree and number of queries.
The next $$$n-1$$$ lines contain three integers $$$x,y,w$$$ $$$(1 \le x,y \le n, x≠y, 1 \le w \le 10^9)$$$ — there is an edge between $$$x$$$ and $$$y$$$ with weight $$$w$$$.
The following $$$q$$$ lines can fall into three cases:
Queries description was mentioned in the problem statement.
For each test, print the required answer for the $$$2^{nd}$$$ and $$$3^{rd}$$$ type queries respectively.
5 51 2 21 5 22 3 22 4 22 02 11 5 6 22 02 1
8 12 14 16
| Name |
|---|


