Bubble Cup V9 A Cowboy Beblop at his computer

View as PDF

Submit solution


Points: 35
Time limit: 0.6s
Memory limit: 64M

Problem type

Cowboy Beblop is a funny little boy who likes sitting at his computer. He somehow obtained two elastic hoops in the shape of 2D polygons, which are not necessarily convex. Since there's no gravity on his spaceship, the hoops are standing still in the air. Since the hoops are very elastic, Cowboy Beblop can stretch, rotate, translate or shorten their edges as much as he wants.

For both hoops, you are given the number of their vertices, as well as the position of each vertex, defined by its X, Y and Z coordinates. The vertices are given in the order they're connected: the 1^{st} vertex is connected to the 2^{nd}, which is connected to the 3^{rd}, etc., and the last vertex is connected to the first one. The hoops are connected if it's impossible to pull them to infinity in different directions by manipulating their edges, without having their edges or vertices intersect at any point – just like when two links of a chain are connected. The polygons' edges do not intersect or overlap.

Cowboy Beblop is fascinated with the hoops he has obtained and he would like to know whether they are connected or not. Since he's busy playing with his dog, Zwei, he'd like you to figure it out for him. He promised you some sweets if you help him!

Input Specification

The first line of input contains an integer N, which denotes the number of edges of the first polygon.

The next N lines each contain the integers X, Y and Z - coordinates of the vertices, in the manner mentioned above.

The next line contains an integer M, denoting the number of edges of the second polygon, followed by M lines containing the coordinates of the second polygon's vertices.

Output Specification

Your output should contain only one line, with the words YES or NO, depending on whether the two given polygons are connected.

Constraints

  • 3 \le N \le 10^5
  • 3 \le M \le 10^5
  • -10^6 \le X, Y, Z \le 10^6
  • It is guaranteed that both polygons are simple (no self-intersections), and in general that the obtained polygonal lines do not intersect each other. Also, you can assume that no 3 consecutive points lie on the same line.

Sample Input

4
0 0 0
2 0 0
2 2 0
0 2 0
4
1 1 -1
1 1 1
1 3 1
1 3 -1

Sample Output

YES

Explanation

In the picture below, the two polygons are connected, as there is no way to pull them apart (they are shaped exactly like two square links in a chain). Note that the polygons do not have to be parallel to any of the xy-,xz-,yz- planes in general.


Comments


  • 5
    d  commented on July 10, 2017, 2:42 p.m.

    In case the question is not clear, all vertices in a polygon are coplanar.