Tree And Extra Edge

hard
<a href="https://www.codechef.com/problems/TREEDGE">https://www.codechef.com/problems/TREEDGE</a>

Input Format

.

Output Format

.

Constraints

.

Notice

.

Example

Input
1
7 3
1 2 1
1 3 -2
2 4 3
2 5 -4
5 7 5
3 6 6
2 3 1
5 4 2
5 6 0
Output
10
7
5
Previous
Longest Good Segment

Related Questions