Attraction Score
Time limit4sMemory limit1024 MB
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 cities, numbered from to , in the fictional country of Manteiv. The cities lie on a flat plane, and city is at coordinates . No two cities share a position.
There are highways, numbered from to . Each highway is a line segment joining two different cities and , and it has 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 is defined as follows.
For every pair with such that cities and are both in and connected by a highway, add the number of attraction points on that highway to the score. Let be the number of pairs with such that cities and are both in but not connected by a highway. 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. The attraction score of is . The score of is . The score of is . The score of is .
Find the maximum attraction score among all non-empty subsets of cities .
Input
The first line contains two integers and (, ). Each of the next lines contains and (). Each of the next lines contains , , and (, ). The highways satisfy the conditions stated in the problem.
Output
Output one integer, the maximum attraction score among all non-empty subsets of cities.