Attraction Score
시간 제한4초메모리 제한1024 MB
도로가 서로 교차하지 않는 평면 그래프에서, 고른 도시들의 도로 가중치 합에서 연결되지 않은 쌍 수의 제곱에 10^6을 곱한 값을 뺀 점수의 최댓값을 구한다.
문제
There are cities, numbered from to , 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 . No two cities are located at the same position.
There are highways, numbered from to , 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 has attraction points and connects cities and 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 is defined as follows:
- For every pair of integers where , cities and are in , and they are connected by a highway, add the number of attraction points on the highway to the score.
- Let be the number of pairs of integers where , cities and are in , and they are not connected by a highway. The score incurs a penalty (negative) score of multiplied by the square of . In other words, subtract from the score.
For example, let , cities and be connected by a highway with attraction points, cities and be connected by a highway with attraction points, and cities and not be connected by a highway.
- The attraction score of the subset of cities is .
- The attraction score of the subset of cities is .
- The attraction score of the subset of cities is .
- The attraction score of the subset of cities is .
As an advisor to the ministry, you would like to find the maximum attraction score among all possible non-empty subsets of cities .
입력
The first line of input contains two integers and (; ). Each of the next lines contains two integers. The -th line contains and (). Each of the next lines contains three integers. The -th line contains , , and (; ). 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 .