Shera and His New Job..

4

1 votes
Medium, Graph, Tree, Recruit, Depth-first search, Approved
Problem

Shera has been recently placed in Flipkart, an e-commerce company. His manager gave him a task to complete.

Task: Shera is given a tree hierarchy of items, their categories, sub-categories of the company such that it forms a tree like structure. Each one of them is having a key number from 1 to 'n'(count of all of them). But the key numbers are unordered.

Example:

As Diwali is round the corner so Shera has been asked to design a program that introduces a discount 'd' on any category,sub-category or product which will help in easily applying discounts, to the company.

He also needs to tell the discount on a particular product when queried, this will help process user requests about discount.

Since Shera is new to the company and not so good in maths, so you need to help him complete this task so he can impress his manager.

Input: You are given 'n' - the products,category and sub-categories key value limit. This is followed by n-1 lines containing (u,v) which represents a link between key(u) and key(v), representing the tree structure. Next line contains 'q' - number of queries. Next 'q' lines contains queries of the form:

  • U x y - Update products under key(x) with 'y'% discount.
  • Q x - Output the discount on product x.

Output: For each query of type - "Q x", output the discount on product x at that particular instant.

Note:

  • "All products" always has a key value 1 and all categories, sub-categories and products lie under it.
  • Products will be the leaf nodes in the tree.
  • Query for discount will always be on products.
  • Initially all products have 0% discount.

Constraints:

1<=n,q<=100000

1<=u,v<=n

0<=y<=60

'x' with Q will only be the key of products.

'x' with U can be any key from [1,n].

Time Limit: 2
Memory Limit: 256
Source Limit:
Editor Image

?