Stake Coordinate Reconstruction
Time limit1sMemory limit128 MB
Given squared side lengths of triangles connecting numbered stakes in counter-clockwise order, reconstruct integer coordinates of every stake, with the first three fixed.
- Level
Hard8 of 10
- Topics
- Graph, Geometry, BFS, Implementation
- Solved
- No attempts yet
Problem
Stakes have been driven into a grassy field where a new math building will go, and you must reconstruct their coordinates.
Surveying shows that the first three stakes form a right-angled triangle whose legs are each metre long and whose hypotenuse is metres long. These three stakes are placed at coordinates , , and ; that is, stakes , , and are at , , and respectively. All of the other stakes also land exactly on lattice points (points with integer coordinates).
Given the triangle measurements, determine the coordinates of every stake.
Input
The input consists of several test cases. The first line of each test case contains two integers and , each at least and at most . The integer is the number of lines that follow, and is the number of stakes. The stakes are numbered to , and all stakes are at distinct locations. Each stake's and coordinates are between and inclusive.
Each of the following lines contains exactly six integers , , , , , . The integers , , are the numbers of three stakes, always listed in counter-clockwise order: moving from stake to stake to stake , you turn left at stake . The value is the square of the distance from stake to stake , is the square of the distance from stake to stake , and is the square of the distance from stake to stake .
Every stake appears in at least one line. Moreover, for every pair of stakes , there is a subset of the triangles forming a sequence such that and share two vertices for all , with a vertex of and a vertex of . The last line of input is ; these zeros are not values of and and must not be processed as such.
Output
For each test case, output exactly lines describing stakes to in order. Each line contains two integers, the and coordinates of that stake, separated by a space. The first three lines of output for each test case are always:
0 0
0 1
1 0