#P5540. [BalkanOI 2011] timeismoney

[BalkanOI 2011] timeismoney

Description

Given an undirected graph with nn vertices and mm edges, the ii-th edge has two weights aia_i and bib_i.

Find a spanning tree TT of this graph such that

$$\left(\sum_{e\in T}a_e\right)\times\left(\sum_{e\in T}b_e\right)$$

is minimized.

Input Format

The first line contains two positive integers n,mn,m.

The next mm lines each contain 44 integers ui,vi,ai,biu_i,v_i,a_i,b_i, meaning that the ii-th edge connects uiu_i and viv_i, with weights aia_i and bib_i.

The vertices are numbered from 00 to n1n-1.

Output Format

Suppose the spanning tree you found is TT. Output one line with two integers, which are eTae\displaystyle\sum_{e\in T}a_e and eTbe\displaystyle\sum_{e\in T}b_e.

If there are multiple solutions, output the one with the smallest eTae\displaystyle\sum_{e\in T}a_e.

4 5
0 1 1 2
0 2 2 3
0 3 1 5
1 3 3 4
2 3 1 3
3 10

Hint

For 100%100\% of the testdata, 1n2001\leq n\leq 200, 1m100001\leq m\leq 10000, 0ai,bi2550\leq a_i,b_i\leq 255.

Translated by ChatGPT 5