|
||||||||||
SuccessorTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 7389 Accepted Submission(s): 1754 Problem Description Sean owns a company and he is the BOSS.The other Staff has one Superior.every staff has a loyalty and ability.Some times Sean will fire one staff.Then one of the fired man¡¯s Subordinates will replace him whose ability is higher than him and has the highest loyalty for company.Sean want to know who will replace the fired man. Input In the first line a number T indicate the number of test cases. Then for each case the first line contain 2 numbers n,m (2<=n,m<=50000),indicate the company has n person include Sean ,m is the times of Sean¡¯s query.Staffs are numbered from 1 to n-1,Sean¡¯s number is 0.Follow n-1 lines,the i-th(1<=i<=n-1) line contains 3 integers a,b,c(0<=a<=n-1,0<=b,c<=1000000),indicate the i-th staff¡¯s superior Serial number,i-th staff¡¯s loyalty and ability.Every staff ¡®s Serial number is bigger than his superior,Each staff has different loyalty.then follows m lines of queries.Each line only a number indicate the Serial number of whom should be fired. Output For every query print a number:the Serial number of whom would replace the losing job man,If there has no one to replace him,print -1. Sample Input
Sample Output
Author FZU Source | ||||||||||
|