QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 1024 MB Total points: 100

#3747. Steiner Tree

統計

Bobo has a connected undirected simple graph with $n$ vertices and $m$ edges. The vertices are numbered by $1, 2, \dots, n$ conveniently, and the $i$-th edge has weight $c_i$.

For each integer $k \in [2, n]$, Bobo would like to choose a subset of edges to connect the vertices $1, 2, \dots, k$ with each other. The minimum sum of weight of valid subsets is denoted as $f(k)$.

Find the value of $f(2), f(3), \dots, f(n)$.

Input

The input consists of several test cases and is terminated by end-of-file.

The first line of each test case contains two integers $n$ and $m$.

The $i$-th of the following $m$ lines contains $3$ integers $a_i$, $b_i$ and $c_i$ which denote the edge between vertices $a_i$ and $b_i$ with weight $c_i$.

Output

For each test case, print $(n - 1)$ integers which denote $f(2), f(3), \dots, f(n)$.

Sample Input

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

Sample Output

2
3
3
1
3
6

Constraint

  • $2 \leq n \leq 26$
  • $n - 1 \leq m \leq \frac{n(n - 1)}{2}$
  • $1 \leq a_i, b_i \leq n$
  • $1 \leq c_i \leq 1000$
  • The number of test cases does not exceed $100$.
  • The number of test cases with $n > 8$ does not exceed $5$.

Discussions

About Discussions

The discussion section is only for posting: Editorials, General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues. Submitting multiple issues may cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.