ICPC Asia Pacific Championship 2024 — B. Attraction Score
Problem B

Attraction Score

Time limit: 4 seconds

There are \(n\) cities, numbered from \(1\) to \(n\), in the fictional country of Manteiv. We can consider these cities to be on a flat plane with a 2D coordinate system, where city \(i\) is at coordinates \((x_i, y_i)\). No two cities are located at the same position.

There are \(m\) highways, numbered from \(1\) to \(m\), each of which is a line segment with two different cities as its endpoints and has a number of attraction points alongside it. Specifically, highway \(j\) has \(a_j\) attraction points and connects cities \(u_j\) and \(v_j\) as its endpoints. Having intersections on highways causes traffic jams, and building a highway on top of another highway costs a lot of money. Therefore, it is guaranteed that

The Manteiv Ministry of Tourism would like to choose a subset of cities as tourist attractions. Intuitively, the ministry would like many pairs of chosen cities to be connected by a highway with many attraction points. Formally, the attraction score of a non-empty subset of cities \(S\) is defined as follows:

For example, let \(n = 3\), cities \(1\) and \(2\) be connected by a highway with \(10\) attraction points, cities \(2\) and \(3\) be connected by a highway with \(20\) attraction points, and cities \(1\) and \(3\) not be connected by a highway.

As an advisor to the ministry, you would like to find the maximum attraction score among all possible non-empty subsets of cities \(S\).

Input

The first line of input contains two integers \(n\) and \(m\) (\(1 \le n \le 100\,000\); \(0 \le m \le 300\,000\)). Each of the next \(n\) lines contains two integers. The \(i\)-th line contains \(x_i\) and \(y_i\) (\(0 \le x_i, y_i \le 10^9\)). Each of the next \(m\) lines contains three integers. The \(j\)-th line contains \(u_j\), \(v_j\), and \(a_j\) (\(1 \le u_j \lt v_j \le n; 0 \le a_j \le 10^6\)). The highways are guaranteed to satisfy the conditions in the problem statement.

Output

Output an integer representing the maximum attraction score among all possible non-empty subsets of cities \(S\).

Sample Input #1
3 2
0 0
0 1
1 0
1 2 10
2 3 20
Sample Output #1
20

Explanation for the sample input/output #1

This sample is the example given in the problem statement above. The subset of cities \(\{2, 3\}\) gives the highest attraction score of \(20\).

Sample Input #2
3 3
0 0
0 1
1 0
1 2 10
2 3 20
1 3 30
Sample Output #2
60

Explanation for the sample input/output #2

The cities and highways are illustrated by Figure B.1. By choosing cities \(1\), \(2\), and \(3\) in \(S\), the attraction score would be \(10 + 20 + 30 - 10^6 \times 0^2 = 60\).

Triangle of cities 1, 2, 3 with highways A1 = 10, A2 = 20, A3 = 30
Figure B.1: Illustration of sample input #2.