Coordinates
Time limit3sMemory limit512 MB
Given differences in x and y between pairs of bases, reconstruct each base's coordinate, fixing base 1 at (0,0).
- Level
Medium4 of 10
- Topics
- Graph, BFS, DFS, Implementation
- Solved
- No attempts yet
Problem
You advise a galactic empire that wants to locate every rebel base on the planet Taboo. The map of Taboo is a grid of size , and the position of a base is a coordinate with .
The empire captured rebels who surrendered and interrogated them about the bases. Each captured rebel only tells how far apart two bases are along the axis and along the axis. Reconstruct coordinates for all bases that agree with every interrogation.
Input
The first line contains the number of bases and the number of captured rebels . (, )
Each of the next lines contains four integers , , , . (, ) The coordinate of base minus the coordinate of base is , and the coordinate of base minus the coordinate of base is .
The interrogations never contradict each other, and they determine the position of every base.
Output
Print lines. Line contains the coordinates and of base , separated by a space.
Translating the whole map keeps every interrogation satisfied. To make the answer unique, print the coordinates that place base 1 at . Under that rule the absolute value of every printed coordinate is at most .