QOJ.ac

QOJ

حد الوقت: 5 s حد الذاكرة: 512 MB مجموع النقاط: 100 قابلة للهجوم ✓

#5296. Planar Graph

الإحصائيات

In a planar graph with $n$ vertices and $m$ line segments, the $i$-th vertex has coordinates $(x_i, y_i)$, and the $j$-th line segment connects vertex $u_j$ and vertex $v_j$ with a weight $h_j$. The line segment $j$ does not pass through any other vertices except $u_j$ and $v_j$. If any two line segments have a common point, that point must be a vertex, and both line segments must be connected to that vertex. For any two vertices $x$ and $y$, there always exists a sequence of vertices $a_1, a_2, \dots, a_k$ such that $a_1 = x, a_k = y$, and for any $1 \leq i < k$, $a_i$ and $a_{i + 1}$ are directly connected by a line segment.

These $m$ line segments divide the entire plane into several regions. Only one region is infinite, while the others are bounded. We call the infinite region the "forbidden zone."

You are given $q$ queries. Each query provides two points $A$ and $B$ in the plane that are not vertices and do not lie on any line segment. You need to draw a curve connecting $A$ and $B$ such that the curve does not pass through the forbidden zone or any vertex, and the maximum weight of the line segments crossed by the curve is minimized. For each query, output this minimum possible value.

Input

The first line contains two positive integers $n$ and $m$, representing the number of vertices and the number of line segments, respectively.

The next $n$ lines each contain two integers, where the $i$-th line (the $(i+1)$-th line in total) contains the coordinates $(x_i, y_i)$ of vertex $i$.

The next $m$ lines each contain three positive integers $u, v, h$, representing a line segment connecting vertex $u$ and vertex $v$ with weight $h$, where $u \neq v$.

The next line contains a positive integer $q$, representing the number of queries.

The next $q$ lines each contain four real numbers $A_x, A_y, B_x, B_y$, representing a query with two points at coordinates $(A_x, A_y)$ and $(B_x, B_y)$.

Output

Output $q$ lines, each containing a single integer representing the answer to each query. Specifically, if no edge needs to be crossed to reach the destination, output $0$; if no valid curve exists, output $-1$.

Examples

Input 1

9 12
1 1
1 2
1 3
2 1
2 2
2 3
3 1
3 2
3 3
1 2 10
2 3 10
3 6 10
6 9 10
9 8 10
8 7 10
7 4 10
4 1 10
2 5 3
5 8 2
5 6 4
4 5 1
3
1.5 1.5 2.5 2.5
1.5 2.5 2.5 1.5
0.5 0.5 1.5 1.5

Output 1

2
3
-1

Note

(No image available)

Constraints

This problem consists of 10 test cases. The scale and characteristics of each test case are as follows:

Test Case ID Range of $n, m, q$ Range of $x, y$ Other Characteristics
1 $n = 10, m = 13, q = 20$ .h=2 $0 \leq x \leq 1, 0 \leq y \leq 2000$ .h=5 All line segment lengths are equal to $1$
2 $n = 2012, m = 3016, q \leq 1000$
3 $n, m \leq 50, q \leq 200$ .h=3 $0 \leq x, y \leq 1000$
4 .h=2 $n, m \leq 100000, q \leq 100000$
5
6 .h=2 $n, m \leq 2000, q \leq 2000$ .h=5 $0 \leq x, y \leq 10^7$ Each bounded region is a convex polygon and all line segment weights are equal to $1$
7 All line segment weights are equal to $1$
8 .h=3 $n, m \leq 100000, q \leq 100000$ .h=3 None
9
10

For all data, $5 \leq n, m \leq 100000$, and the weight of any line segment does not exceed $10^9$. All query coordinates are non-negative real numbers not exceeding $10^7$, and are guaranteed to be odd multiples of $0.5$.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.