F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Road Discount

Time Limit: 6000/6000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 708    Accepted Submission(s): 296


Problem Description
There are $n$ cities in Byteland, labeled by $1$ to $n$. The Transport Construction Authority of Byteland is planning to construct $n-1$ bidirectional roads among these cities such that every pair of different cities are connected by these roads directly or indirectly.

The engineering company has offered $m$ possible candidate roads to construct. The $i$-th candidate road will cost $c_i$ dollars, and if it is finally constructed, there will be a road connecting the $u_i$-th city and the $v_i$-th city directly. Fortunately, each road has its discounted price, the $i$-th of which is $d_i$.

The Transport Construction Authority of Byteland can buy at most $k$ roads at their discounted prices. Please write a program to help the Transport Construction Authority find the cheapest solution for $k=0,1,2,\dots,n-1$.
 

Input
The first line contains a single integer $T$ ($1 \leq T \leq 10$), the number of test cases. For each test case:

The first line contains two integers $n$ and $m$ ($2 \leq n \leq 1\,000$, $n-1\leq m\leq 200\,000$), denoting the number of cities and the number of candidate roads.

Each of the following $m$ lines contains four integers $u_i,v_i,c_i$ and $d_i$ ($1 \leq u_i,v_i \leq n$, $u_i\neq v_i$, $1\leq d_i\leq c_i\leq 1\,000$), describing a candidate road.
 

Output
For each test case, output $n$ lines, the $i$-th ($1\leq i\leq n$) of which containing an integer, denoting the cheapest total cost to construct $n-1$ roads when $k=i-1$.

It is guaranteed that the answer always exists.
 

Sample Input
1 5 6 1 2 1 1 2 3 2 1 2 4 3 2 2 5 4 3 1 3 5 3 4 5 6 1
 

Sample Output
10 7 6 5 5
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-05-11 17:19:57, Gzip enabled