#P13824. 「Diligent-OI R2 D」在水一方

    ID: 13568 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>动态规划 DP二分2025洛谷原创最近公共祖先 LCA扫描线洛谷月赛双指针 two-pointer

「Diligent-OI R2 D」在水一方

Description

The computer lab is enormous and intricately structured. It contains nn junction points, each described by two parameters xi,yix_i,y_i. The podium is also considered a junction point, numbered 11. The "NC2 distance" from the ii-th junction point to the jj-th junction point is (xixj)2+(yiyj)2(x_i-x_j)^2+(y_i-y_j)^2.

There are n1n-1 bi-directional passages connecting all junction points, forming a tree with the podium as the root. The length of each passage is the "NC2 distance" between the connected junction points.

People can only walk along passages and cannot divert into another passage midway. However, snacks can be thrown and passed between two points with an "NC2 distance" of no more than dd.

Klg and acmp's raiding plan is as follows:

  • They select two junction points p,qp,q (with pqp\le q). Klg starts at pp and acmp starts at qq. The shortest path formed by passages connecting pp and qq is the "activity path".
  • Each time, they pass snacks between them, requiring the "NC2 distance" between their current junction points to not exceed dd. Note that they must also pass snacks when they are initially at pp and qq.
  • After each snack pass, at least one of them must move exactly one passage toward the podium before the next snack pass. However, both must remain on the "activity path" throughout.
  • The raid stops and is considered successful when they are at the same junction point during a snack pass.

Klg and acmp have planned tt raids, with dd potentially changing each time. Ns6 needs to know, for each plan, if it can succeed, what is the maximum possible length of the "activity path" (i.e., the sum of the lengths of each passage on the "activity path")? Please output p,qp,q under this condition. If there are multiple solutions, output the one with the smallest pp, and if still multiple, the one with the smallest qq.

Note that the distance between two points in this problem is "NC2 distance", not Euclidean distance.

Input Format

The first line contains two integers n,tn,t.

The next nn lines each contain two integers (xi,yi)(x_i,y_i).

The next n1n-1 lines each contain two integers u,vu,v representing a passage connecting junction points uu and vv.

The next tt lines each contain one integer representing dd for that query.

Output Format

Output tt lines, each containing two integers representing the satisfying p,qp,q.

12 4
10 10
9 7
13 9
5 6
3 4
7 4
10 4
11 4
13 4
5 1
8 1
10 2
1 2
1 3
2 4
4 5
4 6
3 7
3 8
3 9
6 10
8 11
8 12
9
20
45
1
7 12
7 11
10 11
7 8

Hint

Sample #1 Explanation:

The structure of the computer lab in the sample is as follows:

Taking the first raid as an example:

The x,yx,y of points 77 and 1212 are (10,4)(10,4) and (10,2)(10,2), respectively.

The length of the active path between 77 and 1212 is 34+29+5=6834+29+5=68.

Initially, the two are at 77 and 1212, with an "NC2 distance" of 44.

In the second step, they are at 77 and 88, with an "NC2 distance" of 11.

In the third step, they are both at 33, and the raid ends.

It can be proven that there is no better solution.

Data Range

All data guarantees: $3\le n\le 1000,1\le t\le 10^5,0\le x_i,y_i\le 10^6,0\le d\le2\times10^{12}$.

  • Subtask 1 (20pts): n10,t5n\le10,t\le5.
  • Subtask 2 (15pts): n100,t5n\le100,t\le5.
  • Subtask 3 (25pts): t5t\le5.
  • Subtask 4 (10pts): Each junction point is connected to at most two passages.
  • Subtask 5 (30pts): No special properties.