#P9542. [湖北省选模拟 2023] 棋圣 / alphago

    ID: 10585 远端评测题 2000ms 1024MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>动态规划 DP图论2023O2优化二分图Ad-hoc湖北

[湖北省选模拟 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 nn vertices and mm edges, with no multiple edges and no self-loops. Also, each edge has a weight, and the weight of the ii-th edge is wiw_i.

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 uu 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 vv, the player must choose any simple path from vv to uu, and move this stone one step along this simple path. Formally, a simple path is a vertex sequence {p1,p2pk}\{p_1,p_2 \ldots p_k\} that satisfies p1=vp_1 = v, pk=up_k = u, p1,p2pkp_1,p_2 \ldots p_k are all distinct, and there is an edge between pip_i and pi+1p_{i+1}. After the operation, this stone will be moved to vertex p2p_2.

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 00), 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 ww, then we say they enclose this edge, which gives the player ww 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 m+k+1m + k + 1 lines.

The first line contains three integers n,m,kn,m,k, denoting the number of vertices, edges, and stones.

The next kk lines each contain two integers x,cx,c, meaning there is a stone of color cc on vertex xx. Here c=0c=0 means a black stone, and c=1c=1 means a white stone.

The next mm lines each contain three integers u,v,wu,v,w, meaning there is an edge connecting uu and vv with weight ww.

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 33, then move the black stone on vertex 11 to vertex 22, and move the black stone on vertex 22 to vertex 33. In this way, the two stones are on vertices directly connected by an edge of weight 22, so the produced points are 22.

Subtasks

For all testdata, it is guaranteed that 3n1003 \leq n \leq 100, n1mn(n1)2n-1 \leq m \leq \frac{n(n-1)}{2}, 1kn11 \leq k \leq n-1, 0wi1050 \leq w_i \leq 10^5.

Translated by ChatGPT 5