#P5805. [SEERC 2019] Graph and Cycles
[SEERC 2019] Graph and Cycles
Description
There is an undirected complete graph with vertices and edge weights, where is odd.
A cycle edge group of size is an array of edges that satisfies:
- is greater than .
- For any integer in , the edge shares exactly one common endpoint with each of and (where and ).
Obviously, the edges in a cycle edge group form a cycle in the graph.
Define a function for two edges as the larger of their edge weights.
Define the value of a cycle edge group as the sum of over all integers in (where ).
Define a cycle decomposition of a graph as a set of pairwise disjoint cycle edge groups whose union contains all edges of the graph. Define the value of a cycle decomposition as the sum of the values of all cycle edge groups in it.
A graph may have multiple cycle decompositions. Given a graph, your task is to find the cycle decomposition with the minimum value and output this minimum value.
Input Format
The first line contains an integer , representing the number of vertices in the graph.
The next lines each contain three integers and $w \ (1 \leq u, v \leq n, u \neq v, 1 \leq w \leq 10^9)$, indicating that there is an edge of weight between vertex and vertex .
Output Format
Output one integer, representing the value of the minimum-value cycle decomposition of the given graph.
3
1 2 1
2 3 1
3 1 1
3
5
4 5 4
1 3 4
1 2 4
3 2 3
3 5 2
1 4 3
4 2 2
1 5 4
5 2 4
3 4 2
35
Hint
In the following sample explanations, edges are numbered in input order, and denotes the -th edge in the input order.
In the first sample, the only cycle decomposition is . $f(e_1, e_2) + f(e_2, e_3) + f(e_3, e_1) = 1 + 1 + 1 = 3$.
In the second sample, an optimal cycle decomposition is $S = \{ [e_3, e_8, e_9], [e_2, e_4, e_7, e_{10}, e_5, e_1, e_6] \}$. The value of the cycle edge group is , and the value of is , so the value of the cycle decomposition is .
Translated by ChatGPT 5
京公网安备 11011102002149号