Can anyone solve programming question its really challenging: Indian Olympiad question. | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite
+ 1

Can anyone solve programming question its really challenging: Indian Olympiad question.

Boing Inc, has N employees, numbered 1 … N. Every employee other than Mr. Hojo (the head of the company) has a manager (P[i] denotes the manager of employee i). Thus an employee may manage any number of other employees but he reports only to one manager, so that the organization forms a tree with Mr. Hojo at the root. We say that employee B is a subordinate of employee A if B appears in the subtree rooted at A. Mr. Hojo, has hired Nikhil to analyze data about the employees to suggest how to identify faults in Boing Inc. Nikhil, who is just a clueless consultant, has decided to examine wealth disparity in the company. He has with him the net wealth of every employee (denoted A[i] for employee i). Note that this can be negative if the employee is in debt. He has already decided that he will present evidence that wealth falls rapidly as one goes down the organizational tree. He plans to identify a pair of employees i and j, j a subordinate of i, such that the wealth difference A[i] - A[j] is maximum. 

23rd Sep 2018, 7:09 AM
Utkarsh Sanwal
10 Réponses
0
Well, I think the simplest way is to use DFS and return minimum wealth and maximum wealth difference from each subtree.
23rd Sep 2018, 7:59 AM
Viacheslav
+ 3
Best of luck to you both! 😊👍
23rd Sep 2018, 9:03 AM
Janning⭐
Janning⭐ - avatar
+ 2
Janning⭐ 😁 That's why I am going to solve it, but not now. Anyway, I am busy now. And I want to get acquainted with this representation of trees. I think I have found a way to do something like DFS here without building an explicit tree.
23rd Sep 2018, 8:59 AM
Viacheslav
+ 2
Utkarsh Sanwal , you can post your code request here: https://www.sololearn.com/discuss/1270852/?ref=app Make sure to read the instructions before posting. Post the problem in your feed, and only the link to that post on the page.
23rd Sep 2018, 1:59 PM
Kishalaya Saha
Kishalaya Saha - avatar
+ 1
Your task is to help him do this. Suppose, Boing Inc has 4 employees and the parent (P[i]) and wealth information (A[i]) for each employee are as follows: i 1 2 3 4 A[i] 5 10 6 12 P[i] 2 -1 4 2 P[2] = -1 indicates that employee 2 has no manager, so employee 2 is Mr. Hojo. B In this case, the possible choices to consider are (2,1) with a difference in wealth of 5, (2,3) with 4, (2,4) with -2 and (4,3) with 6. So the answer is 6.
23rd Sep 2018, 7:10 AM
Utkarsh Sanwal
+ 1
Bt i didn't get the answer, can u plzz send me program if u willing to help me☺️
23rd Sep 2018, 8:03 AM
Utkarsh Sanwal
+ 1
So if Viacheslav solves this, who gets to be the Indian Olympiad: Viacheslav or Utkarsh Sanwal ?
23rd Sep 2018, 8:52 AM
Janning⭐
Janning⭐ - avatar
+ 1
I wouldn't want to take away your glory. 😊 If you post code to troubleshoot, I'd consider contributing some guidance.
23rd Sep 2018, 9:47 AM
Janning⭐
Janning⭐ - avatar
0
Thanks Janning bt why u r not helping us😕
23rd Sep 2018, 9:30 AM
Utkarsh Sanwal
0
Ok
23rd Sep 2018, 10:32 AM
Utkarsh Sanwal