NOI '99 P5 - Optimally Connected Subset

View as PDF

Submit solution

Points: 15 (partial)
Time limit: 0.6s
Memory limit: 16M

Problem type
National Olympiad in Informatics, China, 1999

It is well-known that we can uniquely represent any point P on the Cartesian coordinate system using an ordered pair (x,y). If both x and y are integers, then we shall call P an integer point, otherwise we shall call P a non-integer point. We shall denote all integer points on the plane using the set W.

Definition 1: For two points P1(x1,y1),P2(x2,y2), if |x1x2|+|y1y2|=1, then P1 and P2 shall be considered neighbors, which is denoted as P1P2. Otherwise, P1 and P2 are considered non-neighboring.

Definition 2: The set S is a finite subset of W such that S={P1,P2,,Pn} (n1), where Pi (1in) belongs in W. We shall call S a set of integer points.

Definition 3: Where S is a set of integer points, if the points R and T belong to S, and there exists a finite sequence Q1,Q2,,Qk satisfying the following:

  1. Qi belongs to S (1ik);
  2. Q1=R,Qk=T;
  3. QiQi+1 (1ik1) — i.e. Qi and Qi+1 are neighbors; and
  4. QiQj for any 1i<jk.

then we shall say that R and T are connected within set S, where the sequence Q1,Q2,,Qk shall be called a pathway connecting points R and T.

Definition 4: For a set of integer points V, if for any two of V's integer points there exists exactly one pathway connecting them, then V shall be known as a singular set of integer points.

Definition 5: For any integer point on the plane, we can assign it an integer score. Thus, we shall call the sum of the scores of all the points in a set of integer points its total score.

Given a singular set of integer points V, we would like to find the optimally connected subset B, where:

  1. B is a subset of V;
  2. any two integer points in B are connected within B; and
  3. out of the set of integer points satisfying 1. and 2., B is the set where the total score is highest.

Input Specification

Line 1 contains an integer N (2N1000), the number of points in V. Within the following N lines, the i-th line (1iN) contains three space-separated integers Xi, Yi, and Ci (106Xi,Yi106;100Ci100), representing the coordinates of the i-th point along with its score.

Output Specification

The output should consist of one integer, the total score of the optimally connected subset.

Sample Input

Copy
5
0 0 -2
0 1 1
1 0 1
0 -1 1
-1 0 1

Sample Output

Copy
2

Problem translated to English by Alex.


Comments

There are no comments at the moment.