#P14790. [NERC 2025] Irrigation Interlock

[NERC 2025] Irrigation Interlock

题目描述

Two irrigation cooperatives share the same fertile valley. The first cooperative maintains pumps scattered across the fields; the second supervises reservoirs on the surrounding hills. Whenever both cooperatives decide to lay a pair of new pipes, the pipes must intersect — at such an intersection they can install a joint valve. Pipes always follow a straight line segment between a pair of distinct pumps or a pair of distinct reservoirs. Two pipes intersect if they share at least one common point (touching and overlapping pipes are considered intersecting).

You are given the exact coordinates of every pump and every reservoir on a Cartesian plane. For each planning scenario, determine whether the first cooperative can pick two distinct pumps and the second cooperative can pick two distinct reservoirs so that the two straight pipes intersect. If this is possible, report the indices of those pumps and reservoirs; otherwise declare that the project cannot be realized.

输入格式

The first line contains an integer tt (1t1051 \le t \le 10^5) — the number of planning scenarios.

For each planning scenario:

  • The first line contains an integer nn (2n1052 \le n \le 10^5) — the number of pumps managed by the first cooperative.
  • Each of the next nn lines contains two integers xix_i and yiy_i (xi,yi109|x_i|, |y_i| \le 10^9) — the Cartesian coordinates of pump ii. The pump locations are distinct.
  • The next line contains an integer mm (2m1052 \le m \le 10^5) — the number of reservoirs managed by the second cooperative.
  • Each of the next mm lines contains two integers uju_j and vjv_j (uj,vj109|u_j|, |v_j| \le 10^9) — the Cartesian coordinates of reservoir jj. The reservoir locations are distinct.

No pump shares its location with any reservoir.

It is guaranteed that the sum of nn over all planning scenarios does not exceed 21052 \cdot 10^5 and the sum of mm over all planning scenarios does not exceed 21052 \cdot 10^5.

输出格式

For each planning scenario:

  • If the first cooperative can choose two pumps and the second cooperative can choose two reservoirs so that the straight pipes connecting each pair intersect, output four integers p1,p2,r1,r2p_1, p_2, r_1, r_2 — the indices of two chosen pumps (1p1,p2n;p1p21 \le p_1, p_2 \le n; p_1 \ne p_2) and two chosen reservoirs (1r1,r2m;r1r21 \le r_1, r_2 \le m; r_1 \ne r_2).
  • If such an intersection is impossible, output 1-1.
  • In case several valid solutions exist, any one of them is acceptable.
3
4
0 0
4 0
3 3
1 3
5
-1 1
5 1
2 -1
2 4
6 3
4
0 0
1 0
0 1
1 1
4
5 5
6 5
5 6
6 6
3
0 0
4 0
0 2
3
4 -2
4 2
6 1
1 4 1 2
-1
1 2 1 2

提示

:::align{center} :::