luogu#P4730. 孤舟蓑笠翁

    ID: 3712 远端评测题 1000ms 250MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>搜索图论O2优化广度优先搜索 BFS

孤舟蓑笠翁

Background

Background

To protect fish, only the best fishermen are allowed to keep fishing on Dongting Lake. After multiple rounds of selection, only the lone fisherman in a small boat remains on Dongting Lake. In the past, he used to fish, play cards, and spar with other fishermen, but now he is left all alone, and cannot help feeling sad. Those eliminated in the selection—where did they go now? Probably went home to farm and raise pigs.

Problem Description

Description

The martial art he practices in his spare time is called "Left-Right Mutual Combat Technique", said to be created by Zhou Botong.

During practice, the fisherman’s two hands move within a certain vertical plane. Take some point on this plane as the origin, set the positive xx-axis to the right and the positive yy-axis upward to form a Cartesian coordinate system. Then any point in this plane can be represented by coordinates (x,y)(x, y).

This technique has nn stopping points, namely $p_1 = (x_1, y_1), p_2 = (x_2, y_2), \ldots, p_n = (x_n, y_n)$. We can view the training process second by second: at the ii-th second, both hands are located at stopping points. At the end of the ii-th second, the hands move to other stopping points (or they may also stay still).

In the Left-Right Mutual Combat Technique, there are kk special moves. The ii-th special move is: if the left hand is at stopping point viv_i and the right hand is at stopping point uiu_i, then this special move can be performed.

There are also taboos in practicing. While both hands are stopped, if the Manhattan distance between the two hands is less than dmind_{min}, it is easy to lose control. If the Manhattan distance is greater than dmaxd_{max}, then obviously his arms are about to be torn apart. So suppose the left hand is at stopping point ll and the right hand is at stopping point rr, then it must satisfy $d_{min} \leq |x_l - x_r| + |y_l - y_r| \leq d_{max}$.

Moving from one stopping point to another also has rules, and the rules are different for the left and right hands. There are mm movement constraints, each of the form: when the left hand is at stopping point aa it can move to stopping point bb, and when it is at bb it can also move to aa; or when the right hand is at stopping point aa it can move to stopping point bb, and when it is at bb it can also move to aa. At the end of any second, his hands are not that fast, so each hand can make at most one move. Any movement not mentioned above is illegal.

The fisherman hopes to perform a combo. That is, he first performs the ii-th special move, and after tt seconds of movement, he performs the jj-th special move, with iji \neq j.

Given p1,,pnp_1, \ldots , p_n, v1,vkv_1, \ldots v_k, u1,,uku_1, \ldots , u_k, dmind_{min}, dmaxd_{max}, and the mm movement constraints, the fisherman wants to know: after performing the ii-th special move, what is the minimum number of seconds of movement needed to perform some special move whose index is not ii, i.e. the shortest time needed to perform a combo. Output the answer for each 1ik1 \leq i \leq k.

Input Format

Input

The first line contains two positive integers n,mn, m.

The second line contains two non-negative integers dmin,dmaxd_{min}, d_{max}. It is guaranteed that dmindmaxd_{min} \leq d_{max}.

The next nn lines: the ii-th line contains two positive integers x,yx, y, indicating the coordinates of stopping point ii.

The next line contains one positive integer kk.

The next kk lines: the ii-th line contains two positive integers v,uv, u, indicating the ii-th special move. The special move can be performed when the left hand is at stopping point vv and the right hand is at stopping point uu. It is guaranteed that 1v,un1 \leq v, u \leq n, no two special moves are exactly the same, and the Manhattan distance between vv and uu is not less than dmind_{min} and not greater than dmaxd_{max}.

The next mm lines: each line contains three positive integers a,b,typea, b, type. If type=0type = 0, it means the left hand can move from stopping point aa to stopping point bb and also from bb to aa. If type=1type = 1, it means the right hand can move from stopping point aa to stopping point bb and also from bb to aa. It is guaranteed that 1a,bn1 \leq a, b \leq n, type{0,1}type \in \{0, 1\}.

Output Format

Output

Output kk lines. The ii-th line should contain the shortest time needed for the ii-th special move to perform a combo once.

If it is impossible to perform a combo no matter what, output 1-1.

5 5
1 6
3 2
9 2
7 3
7 8
4 9
3
5 4
1 3
1 2
1 2 0
2 5 0
1 5 1
1 3 1
3 4 1
2
2
-1
6 14
2 7
3 10
8 9
3 4
6 5
3 10
6 7
4
6 2
1 2
5 2
3 6
5 2 0
4 5 1
2 3 1
5 4 0
1 2 1
1 4 0
6 4 1
5 4 1
4 6 0
1 5 0
4 1 0
6 4 0
5 5 0
1 2 0
2
1
1
-1

Hint

[Sample Explanation]

Explain

Explanation for Sample 1. For special move 11, you can first move the left hand to stopping point 22 and the right hand to stopping point 33 at the same time, which costs 1 s1 \textrm{ s}. Then move the left hand to stopping point 11 and keep the right hand still; then you can perform special move 22, taking a total of 2 s2 \textrm{ s}. For special move 22, you can reverse the above process to perform special move 11. For special move 33, the right hand cannot move in any way, so no special move can be performed, hence output 1-1.

Explanation for Sample 2. Omitted.

[Constraints]

Constraint

For 20%20\% of the testdata, n50n \leq 50, m100m \leq 100, k100k \leq 100.
For another 30%30\% of the testdata, n500n \leq 500, m2000m \leq 2000, k10000k \leq 10000, dmin=0d_{min} = 0, dmax=10000d_{max} = 10000.
For 100%100\% of the testdata, n1000n \leq 1000, m4000m \leq 4000, 1xi,yi10001 \leq x_i, y_i \leq 1000, 0dmindmax1090 \leq d_{min} \leq d_{max} \leq {10}^9.

Translated by ChatGPT 5