8978: link with Railway Company

内存限制:256 MB 时间限制:1 S
题面:传统 评测方式:文本比较 上传者:
提交:0 通过:0

题目描述

link is the owner of a railway company. The railway company currently operates nnn stations and mmm railway lines.

The railway network consists of n−1n-1n1 bidirectional railways, and any two stations can be reached from each other through the railway network. The railways in the network can be represented by n−1n-1n1 triplets (ui,vi,ci)(u_i, v_i, c_i)(ui,vi,ci), where uiu_iui and viv_ivi are the starting and ending stations of the railway, and cic_ici is the daily maintenance cost for that railway.

The operated transport lines of the company can be represented by mmm quadruplets (ai,bi,xi,yi)(a_i, b_i, x_i, y_i)(ai,bi,xi,yi). Here, aia_iai and bib_ibi are the starting and ending stations of the line, xix_ixi represents the daily revenue generated by the line, and yiy_iyi represents the additional expenses incurred by operating this line daily.

The company is currently undergoing a reform: abandoning some underperforming lines and stopping maintenance on certain railways to improve the company's profitability.

link wants to know, in the optimal state, what is the maximum daily revenue the company can achieve after the reform?

输入格式

The first line contains two integers, nnn and mmm (2≤n≤104,1≤m≤104)(2 \leq n \leq 10^4, 1 \leq m \leq 10^4)(2n104,1m104).

The next n−1n-1n1 lines contain three integers each, uiu_iui, viv_ivi, and cic_ici (1≤ui,vi≤n,ui≠vi,1≤ci≤105)(1 \leq u_i, v_i \leq n, u_i \neq v_i, 1 \leq c_i \leq 10^5)(1ui,vin,ui=vi,1ci105), representing a railway.

The next mmm lines contain four integers each, aia_iai, bib_ibi, xix_ixi, and yiy_iyi (1≤ai,bi≤n,ai≠bi,1≤xi,yi≤105)(1 \leq a_i, b_i \leq n, a_i \neq b_i, 1 \leq x_i, y_i \leq 10^5)(1ai,bin,ai=bi,1xi,yi105), representing a transport line operated by the company.

It is guaranteed that any two stations can be reached from each other through the railway network.

输出格式

Output a single integer on a line, representing the maximum daily revenue.

输入样例 复制

3 2
1 2 2
1 3 2
2 3 2 1
1 2 4 1

输出样例 复制

1

分类标签