Rainy City

5

1 votes
Segment Trees, Eulerian path, Data Structures, Trees, Lowest Common Ancestor
Problem

Prakhar lives in a town with N cities and N1 bidirectional roads such that there is a path between every pair of cities. You are given a weather forecast for M days, which specifies a start city, an end city, and the amount of rainfall X that all cities on the simple path between the start and end city (including the start and end cities themselves) will receive. Your task is to help him find the city that will receive the minimum amount of rainfall after M days based on the given forecast. If there are multiple cities with the same minimum rainfall, print the city with the lowest city number.

 

Input format

1st line contains two integers N and M the number of cities and the number of days respectively.

Next N1 lines contains two integers Ai and Bi denoting a road between the respecitve cities.

Next M lines contains 3 integers AiBiX the start city, the end city and the amount of rainfall they recieved respectively.

 

Output format

Print the city with the minimum rainfall recieved after M days. If there are multiple answers, print the one with the least city index.

 

Constraints

1<=N,M<=2105

1<=Ai,Bi<=N

0<=X<=109

Time Limit: 3
Memory Limit: 256
Source Limit:
Explanation

                                                                               

These are the amount of rainfall each city will recieve.

 

Editor Image

?