#ahc020a. [ahc020_a]Broadcasting

[ahc020_a]Broadcasting

Story

AtCoder regularly broadcasts its official live broadcast "A-Da-Coder" on the Internet to provide the latest news and to interact with users. To reach a wider audience, CEO Takahashi decided to build a TV network to broadcast the live stream to all residents of AA City.

The TV network of AA city is represented by a weighted planar undirected graph with broadcast stations as vertices and cables between stations as edges. AtCoder's office is located in the same building as broadcast station 11 located at coordinates (x1,y1)=(0,0)(x_1, y_1) = (0, 0). You can turn power ON/OFF for each cable, and each station that can be reached from the station 11 using only the cables with power ON can transmit radio waves for broadcasting. You can adjust the output strength of the broadcast radio waves for each station, and the area in which live broadcasts are delivered depends on the output strength.

Please build a TV network that can deliver live broadcasts to all residents while reducing the cost of using transmission cables and the cost of transmitting radio waves for broadcasts.

Problem Statement

You are given a weighted planar undirected graph GG with NN vertices and MM edges. The coordinates of vertex ii are (xi,yi)(x_i, y_i). The jj-th edge connects vertices uju_j and vjv_j with the weight wjw_j. Let $D_j=\\mathrm{round}\\left(\\sqrt{(x_{u_j}-x_{v_j})^2+(y_{u_j}-y_{v_j})^2}\\right)$ be the rounded Euclidean distance between vertices uju_j and vjv_j. Then, weight wjw_j satisfies 100Djlewjle2500Dj100D_j\\le w_j\\le 2500D_j. You are also given KK coordinates of the residents, and the coordinates of kk-th resident are (ak,bk)(a_k, b_k).

You should set the power ON/OFF for each edge and the output strength integer Pi(0lePile5000)P_i\\ (0\\le P_i\\le 5000) for each vertex i=1,2,cdots,Ni=1,2,\\cdots,N. Let EE' be the set of edges whose power is ON. Consider a subgraph GG' obtained from GG by removing edges not included in EE', and let VV' be the set of vertices reachable from vertex 11 in GG'. For each iinVi\\in V', residents living within a circular region of radius PiP_i centered at coordinates (xi,yi)(x_i, y_i) (including the circumference) will be able to view the live broadcast.

Setting the power of edge jj to ON incurs a cost wjw_j. Also, setting the output strength of vertex ii to PiP_i incurs a cost Pi2P_i^2. You may set PiP_i to a positive value for inotinVi\\notin V', but this will not expand the broadcasting coverage area and incurs unnecessary costs. Please build a TV network that can deliver live broadcasts to all residents while reducing the sum of the costs S=sumi=1NPi2+sumjinEwjS=\\sum_{i=1}^N{P_i^2}+\\sum_{j\\in E'} w_j as small as possible.

Scoring

Let nn be the number of residents in the coverage area of the live broadcast. Then you will obtain the following score.

  • If nltKn\\lt K, mathrmround(106times(n+1)/K)\\mathrm{round}(10^6 \\times (n+1)/K).
  • If n=Kn=K, mathrmround(106times(1+108/(S+107)))\\mathrm{round}(10^6\\times(1+10^8/(S+10^7))).

Note that SS may not fit into the 32-bit integer.

There are 300 test cases, and the score of a submission is the total score for each test case. The input for seed=0 is manually created and is not included in the test cases. If your submission produces an illegal output or exceeds the time limit for some test cases, the submission itself will be judged as WA