Attraction Score

시간 제한4초메모리 제한1024 MB

요약
도로가 서로 교차하지 않는 평면 그래프에서, 고른 도시들의 도로 가중치 합에서 연결되지 않은 쌍 수의 제곱에 10^6을 곱한 값을 뺀 점수의 최댓값을 구한다.
난이도

어려움10점 중 8점

유형
그래프, 동적 계획법, 그리디, 정렬
정답자
아직 제출이 없습니다

문제

There are nn cities, numbered from 11 to nn, 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)(x\_i , y\_i). No two cities are located at the same position.

There are mm highways, numbered from 11 to mm, 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 jj has a_ja\_j attraction points and connects cities u_ju\_j and v_jv\_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

  • no two highways intersect at any point other than at a city,
  • no highway passes through a city other than its two endpoints, and
  • there is at most one highway connecting each pair of cities.

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 SS is defined as follows:

  • For every pair of integers (a,b)(a, b) where a<ba < b, cities aa and bb are in SS, and they are connected by a highway, add the number of attraction points on the highway to the score.
  • Let f(S)f(S) be the number of pairs of integers (a,b)(a, b) where a<ba < b, cities aa and bb are in SS, and they are not connected by a highway. The score incurs a penalty (negative) score of 10610^6 multiplied by the square of f(S)f(S). In other words, subtract 106×f(S)210^6 × 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 by a highway.

  • The attraction score of the subset of cities 1\\{1\\} is 00.
  • The attraction score of the subset of cities 1,2\\{1, 2\\} is 10−106×02=1010 - 10^6 \times 0^2 = 10.
  • The attraction score of the subset of cities 2,3\\{2, 3\\} is 20−106×02=2020 - 10^6 \times 0^2 = 20.
  • The attraction score of the subset of cities 1,2,3\\{1, 2, 3\\} is 10+20−106×12=−999,97010 + 20 - 10^6 \times 1^2 = -999\\, 970.

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

입력

The first line of input contains two integers nn and mm (1≤n≤100,0001 ≤ n ≤ 100\\, 000; 0≤m≤300,0000 ≤ m ≤ 300\\, 000). Each of the next nn lines contains two integers. The ii-th line contains x_ix\_i and y_iy\_i (0≤x_i,y_i≤1090 ≤ x\_i , y\_i ≤ 10^9). Each of the next mm lines contains three integers. The jj-th line contains u_ju\_j, v_jv\_j, and a_ja\_j (1≤u_j<v_j≤n1 ≤ u\_j < v\_j ≤ n; 0≤a_j≤1060 ≤ a\_j ≤ 10^6). The highways are guaranteed to satisfy the conditions in the problem statement.

출력

Output an integer representing the maximum attraction score among all possible non-empty subsets of cities SS.

예제2

  1. 예제 1

    입력
    3 2
    0 0
    0 1
    1 0
    1 2 10
    2 3 20
    
    예상 출력
    20
    
  2. 예제 2

    입력
    3 3
    0 0
    0 1
    1 0
    1 2 10
    2 3 20
    1 3 30
    
    예상 출력
    60