#P5766. [NOI1999] 最优联通子集
[NOI1999] 最优联通子集
Description
As is well known, we can use the Cartesian coordinate system to uniquely represent any point on the plane by an ordered pair . If both are integers, then we call point a lattice point; otherwise, point is a non-lattice point. Let the set of all lattice points on the plane be denoted by .
Definition 1: For two lattice points , if , then and are said to be adjacent, denoted by ~. Otherwise, they are said to be non-adjacent.
Definition 2: Let a point set be a finite subset of , that is, , where belongs to . We call a lattice point set.
Definition 3: Let be a lattice point set. If points and belong to , and there exists a finite point sequence satisfying:
- belongs to ();
- , ;
- ~ , i.e. and are adjacent;
- For any , ;
then we say point and point are connected in the lattice point set . The point sequence is called a path in connecting and .
Definition 4: If a lattice point set satisfies that for any two lattice points in , there exists one and only one path in connecting these two points, then is called a single lattice point set.
Definition 5: For each lattice point on the plane, we can assign it an integer as the weight of that point. The sum of the weights of all points in a lattice point set is called the weight sum of that set.
For a given single lattice point set , we want to find an optimal connected subset of such that:
- is a subset of .
- Any two lattice points in are connected within .
- Among all lattice point sets satisfying conditions (1) and (2), has the maximum weight sum.
Input Format
The first line contains an integer , indicating the number of points in the single lattice point set .
In the next lines, the -th line contains three integers , which represent the -coordinate, -coordinate, and weight of the -th point, respectively. Adjacent numbers on the same line are separated by one space.
Output Format
Output one integer, the weight sum of the required optimal connected set.
5
0 0 -2
0 1 1
1 0 1
0 -1 1
-1 0 1
2
Hint
Translated by ChatGPT 5
京公网安备 11011102002149号