Under construction

Still being built. Things may change

Coordinates

Time limit3sMemory limit512 MB

Summary
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 108×10810^8 \times 10^8, and the position of a base is a coordinate (x,y)(x, y) with 0≤x,y<1080 \le x, y < 10^8.

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 xx axis and along the yy axis. Reconstruct coordinates for all bases that agree with every interrogation.

Input

The first line contains the number of bases NN and the number of captured rebels MM. (1≤N≤100 0001 \le N \le 100\,000, N≤M≤1 000 000N \le M \le 1\,000\,000)

Each of the next MM lines contains four integers aia_i, bib_i, dxidx_i, dyidy_i. (1≤ai,bi≤N1 \le a_i, b_i \le N, −108≤dxi,dyi≤108-10^8 \le dx_i, dy_i \le 10^8) The xx coordinate of base bib_i minus the xx coordinate of base aia_i is dxidx_i, and the yy coordinate of base bib_i minus the yy coordinate of base aia_i is dyidy_i.

The interrogations never contradict each other, and they determine the position of every base.

Output

Print NN lines. Line jj contains the coordinates xjx_j and yjy_j of base jj, 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 (0,0)(0, 0). Under that rule the absolute value of every printed coordinate is at most 10910^9.

Examples4

  1. Example 1

    Input
    3 3
    1 2 3 0
    2 3 0 3
    1 3 3 3
    
    Expected output
    0 0
    3 0
    3 3
    
  2. Example 2

    Input
    1 1
    1 1 0 0
    
    Expected output
    0 0
    
  3. Example 3

    Input
    2 3
    2 1 5 -4
    1 2 -5 4
    1 2 -5 4
    
    Expected output
    0 0
    -5 4
    
  4. Example 4

    Input
    5 5
    5 4 50 -50
    4 3 -100 3
    3 2 4 17
    2 1 6 -10
    1 5 40 40
    
    Expected output
    0 0
    -6 10
    -10 -7
    90 -10
    40 40