#abc308h. Ex - Make Q
Ex - Make Q
Score : points
问题描述
存在一个简单无向图,具有 个顶点和 条边。初始时所有边都被涂成白色。顶点编号为 到 ,边编号为 到 。第 条边连接顶点 和顶点 ,将其涂黑所需的代价为 。
“构造一个 Q”意味着涂黑四条或更多条边,使得:
- 所有被涂黑的边中除一条外形成一个简单环;
- 不构成该环的那条涂黑边连接了环上一个顶点与环外另一个顶点。
请判断是否可以构造一个 Q。如果可以,请找出构造 Q 的最小总代价。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
There is a simple undirected graph with vertices and edges. The edges are initially painted white. The vertices are numbered through , and the edges are numbered through . Edge connects vertex and vertex , and the cost required to paint it black is .
"Making a Q" means painting four or more edges so that:
- all but one of the edges painted black form a simple cycle, and
- the edge painted black not forming the cycle connects a vertex on the cycle and another not on the cycle.
Determine if one can make a Q. If one can, find the minimum total cost required to make a Q.
Constraints
- , if .
- All input values are integers.
Input
The input is given from Standard Input in the following format:
Output
If one can make a Q, print the minimum total cost required to do so; otherwise, print .
Sample Input 1
5 6
1 2 6
2 3 4
1 3 5
2 4 3
4 5 2
3 5 1
Sample Output 1
15
By painting edges , and ,
- edges , and forms a simple cycle, and
- edge connects vertex (on the cycle) and vertex (not on the cycle),
so one can make a Q with a total cost of . Making a Q in another way costs or greater, so the answer is .
Sample Input 2
4 4
1 2 1
2 3 1
3 4 1
1 4 1
Sample Output 2
-1
Sample Input 3
6 15
2 6 48772
2 4 36426
1 6 94325
3 6 3497
2 3 60522
4 5 63982
4 6 4784
1 2 14575
5 6 68417
1 5 7775
3 4 33447
3 5 90629
1 4 47202
1 3 90081
2 5 79445
Sample Output 3
78154
update @ 2024/3/10 08:45:27