Mr.…
- User
Mr. ــــــــــــــــــــــــــــــــــــــــــرـــــــــــــــــــــــــــــــــــــرـــــــــــــــــــــــــــــــــــ, But it's been a few days since I heard from a reliable source that someone is spying in that organization. From that day to this moment, the mentioned person has not been calm. Even his relatives have mentioned that due to his anxiety, the number of his nerve pill consumption has skyrocketed.
Mr. ــــــــــــــــــــــــــــــــــــــــــ’s advisers, who are very concerned about his health, decided to find the spy but to improve his general condition. The number of employees in the office is very large, and for the small population of advisors and confidants of Mr. Therefore, they decided to ask each employee to immediately announce their name if they suspect someone among their subordinates.
In this office, every employee has a manager except Mr. Suppose employees with natural numbers from 1 to n We have numbered n. (Mr. ) is also one of these n n is the employee) number of the manager of the employee i I am with m i m i We show m m for Mr. ــــــ is also equal to
1 will be −1. Also, each employee has an amount of credit in the office. Employee credit i iam c i c i we call Also, if someone wants to check that the employee i Iam a spy or not, need to spend t i t i It takes minutes.
We say employee A A subordinate employee B B is, if B B. Manager A A or an employee who is the manager A A is subordinate B be B
In order to check the presence of spies among his subordinates, each employee must check all his subordinates whose credit is less than his credit, and as it was said, he needs some time to check each of them. You need to tell each employee how long it will take for that employee to review their subordinates.
P.N.: The name of Mr.
Edit: In this question, it is not possible for two employees, the first employee to be subordinate to the second employee and the second employee to be subordinate to the first employee.
input In the first line, enter the number n n comes.
in each of n n next line in order of three numbers m i m i and c i c i and t i t i they come
1 ≤ n , t i , c i ≤ 100,000 1≤n,t i c i ≤100,000
output on the line i iam from n n output line, the time it takes the employee i Print iam checking its subordinates with lower validity.
Sub-issues Constraint score subproblem 1 5 n ≤ 5000 n≤5000 210 Every employee has more credit than his subordinates 3 20 Each subordinate employee has a maximum of 20 others 4 65 without additional restrictions Example Sample entry 1 5 4 4 80 1 1 40 -1 10 60 3 5 50 4 8 70 Plain text Sample output 1 40 0 240 120 0 c++
- Assistant