National Disaster: Two Towers
Time limit2sMemory limit512 MB
In a rectangle bounded by two towers, decide whether burning circles block every continuous path between the towers, which happens exactly when a connected chain of circles links two opposite walls of the rectangle.
- Level
Medium7 of 10
- Topics
- Geometry, Union-find, Graph, Implementation
- Solved
- No attempts yet
Problem
Indinesia has two fire lookout towers at and with and . Across the country there are hotspots, and the -th hotspot is a circle with radius centered at . A point is safe when it satisfies all of the following conditions.
- ,
- ,
- It does not lie strictly inside any burning area. In other words, for every , the distance from to is at least .
The locations of the two towers are guaranteed to be safe. The two towers can communicate properly if and only if there exists a safe path connecting them. A path is safe if and only if every point on it is safe. Here a path is any continuous curve, and it does not need to be straight.
Determine whether the two towers can communicate properly.
Input
The first line contains five integers , , , and (, , ), denoting the locations and of the two towers and the number of hotspots. Each of the next lines contains three integers , and (, ), denoting the center of the -th hotspot and the radius of its burning area. No two hotspots share the same center.
Output
Print "YES" in a line when the two towers can communicate properly, and "NO" otherwise (without quotes).
Hint
The figure below is an example of a safe path connecting the two lookout towers.

The figure below is an example of a case where no safe path exists.

The two figures below show another example of a safe path connecting the two lookout towers. The point (10, 15) in the upper figure and the point (10, 30) in the lower figure are safe.

