4438: Minimum Spanning Tree

内存限制:128 MB 时间限制:6 S 标准输入输出
题目类型:传统 评测方式:Special Judge 上传者:
提交:0 通过:0

题目描述

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 + bix, your task is to calculate the value of min (f(l), f(l + 1), …, f(r)).

输入格式

The input consists of several test cases terminated by end-of-file. For each test case:

The first line contains four integers nml 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 uiviai 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 ≤ lr ≤ 106
  • 1 ≤ ui, vinuivi
  • 1 ≤ ai ≤ 106
  • − 106bi ≤ 106
  • The sum of n does not exceed 106.
  • The sum of m does not exceed 2 × 106.

输出格式

For each test case, print an integer which denotes the result.

输入样例 复制

5 6 1 5
1 2 3 1
2 3 5 -1
3 4 1 2
4 5 1 -1
5 1 5 3
2 4 3 -1
5 6 1 5
1 2 1 1
2 3 1 2
3 4 1 -10
3 4 2 10
5 1 3 10
2 4 5 -10

输出样例 复制

2
-35