1099 : Minimum Spanning Tree
| 比对Compare | token 相同即通过。中间的空格、制表符、换行可多可少。Matching tokens pass. Extra spaces, tabs, or newlines between them are ignored. |
|---|---|
| 不同则错Differs | token 个数或内容不同即错误。23 与 2 3、02 与 2、2.0 与 2 均视为不同。A different token count or value is wrong. 23 vs 2 3, 02 vs 2, and 2.0 vs 2 all differ. |
| 输入Input | 标准输入,格式见题面。Standard input; format as in the statement. |
| 输出Output | 标准输出。Standard output. |
题目描述Description
Bobo has an undirected connected graph with n vertices and m edges, where the i-th edge is associated with two parameters ai and bi.
Let f(x) be the sum of weights of the edges in the minimum spanning tree when the weight of the i-th edge is ai + bi ⋅ x, your task is to calculate the value of min (f(l), f(l + 1), …, f(r)).
输入格式Input
The input consists of several test cases terminated by end-of-file. For each test case:
The first line contains four integers n, m, l and r, indicating the number of vertices, the number edges and the range of x.
For the next m lines, the i-th line contains four integers ui, vi, ai and bi , indicating that the i-th edge connects vertices ui and vi and the parameters of the i-th edge. It is guaranteed that the graph is connected.
- 2 ≤ n ≤ 105
- n − 1 ≤ m ≤ 2 × 105
- 0 ≤ l ≤ r ≤ 106
- 1 ≤ ui, vi ≤ n, ui ≠ vi
- 1 ≤ ai ≤ 106
- − 106 ≤ bi ≤ 106
- The sum of n does not exceed 106.
- The sum of m does not exceed 2 × 106.
输出格式Output
For each test case, print an integer which denotes the result.
样例Sample
出题Author
ftiasch