#P9542. [湖北省选模拟 2023] 棋圣 / alphago
[湖北省选模拟 2023] 棋圣 / alphago
Problem Description
Xiao K is a Go player. After getting tired of traditional Go, he invented a new kind of Go.
The new Go is a single-player game. The board of this game is an undirected connected graph with vertices and edges, with no multiple edges and no self-loops. Also, each edge has a weight, and the weight of the -th edge is .
At the beginning of the game, each vertex may have one black stone, one white stone, or be empty. At least one vertex is empty. Next, the player needs to perform some operations. Each operation is as follows:
First, choose a vertex that has no stone on it. It can be guaranteed that under the given constraints, such a vertex always exists.
Next, for each stone, if it is on vertex , the player must choose any simple path from to , and move this stone one step along this simple path. Formally, a simple path is a vertex sequence that satisfies , , are all distinct, and there is an edge between and . After the operation, this stone will be moved to vertex .
Note that although at the start there is at most one stone on each vertex, after several operations there may be multiple stones on one vertex. For different stones on the same vertex, the chosen simple paths in one operation may be different.
After performing any number of operations (possibly ), the player may count territory, i.e., settle the game score. For every pair of stones with different colors, if the vertices they are on are directly connected by an edge with weight , then we say they enclose this edge, which gives the player points. The player's total points is the sum of the points produced by all such pairs of stones.
Now Xiao K gives you the initial board configuration. Please help him find the maximum possible points that can be obtained on this board.
Input Format
The input has lines.
The first line contains three integers , denoting the number of vertices, edges, and stones.
The next lines each contain two integers , meaning there is a stone of color on vertex . Here means a black stone, and means a white stone.
The next lines each contain three integers , meaning there is an edge connecting and with weight .
Output Format
Output one line with one integer, the required answer.
3 2 2
1 0
2 1
1 2 1
2 3 2
2
4 4 3
1 1
2 1
3 0
1 2 1
2 3 1
3 4 1
4 1 3
3
见选手目录下的 alphago/alphago3.in 与 alphago/alphago3.ans。
见选手目录下的 alphago/alphago3.in 与 alphago/alphago3.ans。
见选手目录下的 alphago/alphago4.in 与 alphago/alphago4.ans。
见选手目录下的 alphago/alphago4.in 与 alphago/alphago4.ans。
见选手目录下的 alphago/alphago5.in 与 alphago/alphago5.ans。
见选手目录下的 alphago/alphago5.in 与 alphago/alphago5.ans。
Hint
Sample 1 Explanation
For the first sample, you can choose vertex , then move the black stone on vertex to vertex , and move the black stone on vertex to vertex . In this way, the two stones are on vertices directly connected by an edge of weight , so the produced points are .
Subtasks
For all testdata, it is guaranteed that , , , .

Translated by ChatGPT 5