8502: Spanning Tree Game

内存限制:128 MB 时间限制:11 S 标准输入输出
题目类型:传统 评测方式:文本比较 上传者:
提交:1 通过:1

题目描述

Alice and Bob are playing a game on an undirected graph with n vertices and mm edges. The vertices are labeled by 1,2,,n. The edges are labeled by 1,2,,m. The ii-th edge connects the ui-th vertex and the vi-th vertex directly, and its weight will be chosen from the given two values ai and bi.

First, Alice needs to assign weights to all the mm edges such that there are exactly k edges whose weights are taken from a while the weights of other m-k edges are taken from b. Then, Bob needs to choose exactly n-1 edges from the graph such that every pair of different vertices are connected by these n-1 edges directly or indirectly.

The final score of the game is equal to the total weights of the n-1 edges chosen by Bob. Alice wants to maximize the score while Bob wants to minimize it. Please write a program to predict the final score for k=0,1,2,,m if both of the players play optimally.

输入格式

The first line contains a single integer T(1T20), the number of test cases. For each test case:

The first line contains two integers n and m (2n9,n1m30), denoting the number of vertices and the number of edges.

Each of the following mm lines contains four integers ui,vi,ai and bi (1ui,vin1ai,bi1,000,000), describing an edge.

It is guaranteed that the graph is connected.

输出格式

For each test case, output m+1 lines, the i-th (1im+1) of which containing an integer, denoting the final score when k=i-1

输入样例 复制

1
3 3
1 2 4 6
1 3 2 7
2 3 3 5

输出样例 复制

11
9
7
5