python-cpp-html-programs-projects icon indicating copy to clipboard operation
python-cpp-html-programs-projects copied to clipboard

Boleyn salary (Python or cpp only)

Open ArmanKumar21 opened this issue 2 years ago • 4 comments

Hey? Everyone... Help me with this problem.

Boleyn Su runs a company called Acme. There are N employees in the company, and each one of them is represented by a unique employee id whose range lies in [1, N]. Being the head of company, Boleyn's employee id is 1.

Each employee, except Boleyn, has exactly one direct superior. This means that the hierarchial structure of the company is like a tree, where

Boleyn, employee id 1, represents the root node. Each pair of employee is directly or indirectly connected to one another. There is no cycle. Let's represent the salary by the array s = {s[1], s[2], s[3]..., s[N]}, where s[i] is the salary of the ith employee. Salary structure in the company is non-uniform. Even a subordinate may get a higher salary than her superior. Some of the employees in Acme are curious about who gets the kth lowest salary among her subordinates. Help them in solving their query.

Note

1st lowest salary is equivalent to lowest salary, 2nd lowest means lowest salary which is greater that 1st lowest salary, and so on. Salary of each employee is different. It is not necessary that the people who are placed higher on hierarchy will have a greater salary than their subordinates. Input Format The first line contains two space separated integers, N Q, where N is the number of employees in Acme, and Q is the number of queries. Then follows N-1 lines. Each of these lines contain two space separated integers, u p, where p is the superior of u. u and p are employees id. In the next line there are N space separated integers, s[1] s[2] ... s[n], where s[i], i ∈ [1..N], is the salary of ith employee. Then, Q queries follow. Each query contains two space separated integers, v k. See output format for it's definition.

Output format For the first query, print the id of employee who has the kth lowest salary among the subordinates of v. For the subsequent queries, we need to find the kth lowest salary of the subordinates of v+d, where d is the answer of previous query.

Constraints 1 ≤ N ≤ 3104 1 ≤ Q ≤ 3104 1 ≤ s[ i ] ≤ 109, i ∈ [1..N] s[ i ] ≠ s[ j ], 1 ≤ i < j ≤ N 1 ≤ u, p ≤ N, u ≠ p -N ≤ d ≤ N For 1st query, 1 ≤ v ≤ N For later queries, 1 ≤ v+d ≤ N For each query, 1 ≤ K ≤ Number_of_subordinates

Sample Input

8 7 2 1 3 2 4 2 7 4 8 4 5 1 6 5 70 40 60 80 10 20 30 50 2 1 -6 5 -4 1 -5 3 2 1 -5 4 2 2 Sample Output

7 8 7 3 6 2 8

ArmanKumar21 avatar Oct 15 '22 13:10 ArmanKumar21

i can solve this problem. Assign it to me.

aditya-agr avatar Oct 15 '22 14:10 aditya-agr

@anomekumar08 pls assign it to me

akashbiswas0 avatar Oct 15 '22 18:10 akashbiswas0

I am interested in this work Please assign it to me

MrJayendra avatar Oct 15 '22 18:10 MrJayendra

Good morning , We are a team of 3 members from St Francis Institute of Technology (Mumbai , Maharashtra). For our Resource open source project Lab (ROSPL) , we are interested to work on the given issue. Kindly assign this (Boleyn salary) issue to us . Thank You.

Abhigitlog avatar Aug 31 '23 06:08 Abhigitlog