Growing Tree
题号:NC237180
时间限制:C/C++/Rust/Pascal 3秒,其他语言6秒
空间限制:C/C++/Rust/Pascal 256 M,其他语言512 M
64bit IO Format: %lld

题目描述

You are given a weighted tree T with nodes. The initial weight of the edge is C_i, but every day the weight changes by A_i. Thus, its weight will be in day k. Note that the weights might be negative.
The diameter of T is defined as a the maximum distance between any two nodes. Note that because the weights might be negative, it is possible the two nodes determining the diameter are not distinct.
You will observe the tree for days, starting from day 0 until day . You want to find a date which minimizes the diameter. Formally, you need to find an integer such that no other integer in yields a smaller diameter. If there is more than one such integer, you should find a smallest such integer.

输入描述:

The first line contains the number of nodes N, and the number of observing days D.
Each of the next N-1 lines contains four integer S_i, E_i, C_i, A_i, which indicates edge that connects two vertices S_i and E_i, and it has cost C_i in day 0, and it changes by A_i everyday.

输出描述:

On the first line, print the integer  that minimizes the diameter in interval . If there is more than one such integer, find a smallest such integer.
On the next line, print the diameter of tree in day x, when x is the day you found in first line.
示例1

输入

复制
5 5
1 2 20 -3
2 3 10 -3
3 4 22 -2
3 5 26 -3

输出

复制
5
23