Under construction

Still being built. Things may change

Attraction Score

Time limit4sMemory limit1024 MB

Summary
Choose a subset of cities that maximizes the sum of highway attraction points inside the subset, minus 10^6 times the square of the number of non-adjacent city pairs.
Level

Hard8 of 10

Topics
Graph, Brute force
Solved
No attempts yet

Problem

There are nn cities, numbered from 11 to nn, in the fictional country of Manteiv. The cities lie on a flat plane, and city ii is at coordinates (xi,yi)(x_i, y_i). No two cities share a position.

There are mm highways, numbered from 11 to mm. Each highway is a line segment joining two different cities uju_j and vjv_j, and it has aja_j attraction points. Highways never cross except at cities, no highway passes through a city other than its endpoints, and at most one highway connects any pair of cities.

The Manteiv Ministry of Tourism wants to choose a subset of cities as tourist attractions. The ministry wants many pairs of chosen cities joined by a highway with many attraction points. The attraction score of a non-empty subset of cities SS is defined as follows.

For every pair (a,b)(a, b) with a<ba < b such that cities aa and bb are both in SS and connected by a highway, add the number of attraction points on that highway to the score. Let f(S)f(S) be the number of pairs (a,b)(a, b) with a<ba < b such that cities aa and bb are both in SS but not connected by a highway. Subtract 106×f(S)210^6 \times f(S)^2 from the score.

For example, let n=3n = 3, cities 11 and 22 be connected by a highway with 1010 attraction points, cities 22 and 33 be connected by a highway with 2020 attraction points, and cities 11 and 33 not be connected. The attraction score of {1}\{1\} is 00. The score of {1,2}\{1, 2\} is 10−106×02=1010 - 10^6 \times 0^2 = 10. The score of {2,3}\{2, 3\} is 2020. The score of {1,2,3}\{1, 2, 3\} is 10+20−106×12=−99997010 + 20 - 10^6 \times 1^2 = -999970.

Find the maximum attraction score among all non-empty subsets of cities SS.

Input

The first line contains two integers nn and mm (1≤n≤1000001 \le n \le 100000, 0≤m≤3000000 \le m \le 300000). Each of the next nn lines contains xix_i and yiy_i (0≤xi,yi≤1090 \le x_i, y_i \le 10^9). Each of the next mm lines contains uju_j, vjv_j, and aja_j (1≤uj<vj≤n1 \le u_j < v_j \le n, 0≤aj≤1060 \le a_j \le 10^6). The highways satisfy the conditions stated in the problem.

Output

Output one integer, the maximum attraction score among all non-empty subsets of cities.

Examples2

  1. Example 1

    Input
    3 2
    0 0
    0 1
    1 0
    1 2 10
    2 3 20
    
    Expected output
    20
    
  2. Example 2

    Input
    3 3
    0 0
    0 1
    1 0
    1 2 10
    2 3 20
    1 3 30
    
    Expected output
    60