Rainy City
Practice
5 (1 votes)
Segment trees
Eulerian path
Data structures
Trees
Lowest common ancestor
Problem
87% Success 219 Attempts 50 Points 3s Time Limit 256MB Memory 1024 KB Max Code

Prakhar lives in a town with \(N\) cities and \(N-1\) 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 \(N-1\) lines contains two integers \(A_i\) and \(B_i\) denoting a road between the respecitve cities.

Next \(M \) lines contains 3 integers \(A_i\)\(B_i\)\(X\) 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 <= 2*10^5\)

\(1<= A_i, B_i <=N\)

\(0<=X<=10^9\)

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:50
1 votes
Tags:
LoopsHeavy light decompositionHardTreeData Structures
Points:50
3 votes
Tags:
Lowest Common AncestorTreesData Structures
Points:50
6 votes
Tags:
LoopsHardTree