D - Relative Position Editorial /

Time Limit: 2.5 sec / Memory Limit: 1024 MB

配点 : 400400

問題文

座標平面上に 11 から NN の番号がついた NN 人の人がいます。
11 は原点にいます。

次の形式の情報が MM 個与えられます。

  • AiA_i から見て、人 BiB_i は、xx 軸正方向に XiX_iyy 軸正方向に YiY_i 離れた位置にいる

それぞれの人がいる座標を求めてください。一意に定まらないときはそのことを報告してください。

制約

  • 1N2×1051 \leq N \leq 2\times 10^5
  • 0M2×1050 \leq M \leq 2\times 10^5
  • 1Ai,BiN1\leq A_i, B_i \leq N
  • AiBiA_i \neq B_i
  • 109Xi,Yi109-10^9 \leq X_i,Y_i \leq 10^9
  • 入力は全て整数である
  • 与えられる情報は矛盾しない

入力

入力は以下の形式で標準入力から与えられる。

NN MM
A1A_1 B1B_1 X1X_1 Y1Y_1
\vdots
AMA_M BMB_M XMX_M YMY_M

出力

NN 行出力せよ。
ii のいる座標が一意に定まらないとき、ii 行目には undecidable と出力せよ。
ii のいる座標が (si,ti)(s_i,t_i) と一意に定まるとき、ii 行目には si,tis_i,t_i をこの順に空白区切りで出力せよ。


入力例 1Copy

Copy
3 2
1 2 2 1
1 3 -1 -2

出力例 1Copy

Copy
0 0
2 1
-1 -2

33 人の位置関係は下図のようになっています。

図


入力例 2Copy

Copy
3 2
2 1 -2 -1
2 3 -3 -3

出力例 2Copy

Copy
0 0
2 1
-1 -2

33 人の位置関係は下図のようになっています。

図


入力例 3Copy

Copy
5 7
1 2 0 0
1 2 0 0
2 3 0 0
3 1 0 0
2 1 0 0
3 2 0 0
4 5 0 0

出力例 3Copy

Copy
0 0
0 0
0 0
undecidable
undecidable

同じ情報が複数回与えられたり、同じ座標に複数の人がいることもあります。

Score : 400400 points

Problem Statement

There are NN people numbered 11 to NN on a coordinate plane.
Person 11 is at the origin.

You are given MM pieces of information in the following form:

  • From person AiA_i's perspective, person BiB_i is XiX_i units away in the positive xx-direction and YiY_i units away in the positive yy-direction.

Determine the coordinates of each person. If the coordinates of a person cannot be uniquely determined, report that fact.

Constraints

  • 1N2×1051 \leq N \leq 2\times 10^5
  • 0M2×1050 \leq M \leq 2\times 10^5
  • 1Ai,BiN1\leq A_i, B_i \leq N
  • AiBiA_i \neq B_i
  • 109Xi,Yi109-10^9 \leq X_i,Y_i \leq 10^9
  • All input values are integers.
  • The given information is consistent.

Input

The input is given from Standard Input in the following format:

NN MM
A1A_1 B1B_1 X1X_1 Y1Y_1
\vdots
AMA_M BMB_M XMX_M YMY_M

Output

Print NN lines.
If the coordinates of person ii cannot be uniquely determined, the ii-th line should contain undecidable.
If they can be uniquely determined as (si,ti)(s_i,t_i), the ii-th line should contain sis_i and tit_i in this order, separated by a space.


Sample Input 1Copy

Copy
3 2
1 2 2 1
1 3 -1 -2

Sample Output 1Copy

Copy
0 0
2 1
-1 -2

The figure below shows the positional relationship of the three people.

Figure


Sample Input 2Copy

Copy
3 2
2 1 -2 -1
2 3 -3 -3

Sample Output 2Copy

Copy
0 0
2 1
-1 -2

The figure below shows the positional relationship of the three people.

Figure


Sample Input 3Copy

Copy
5 7
1 2 0 0
1 2 0 0
2 3 0 0
3 1 0 0
2 1 0 0
3 2 0 0
4 5 0 0

Sample Output 3Copy

Copy
0 0
0 0
0 0
undecidable
undecidable

The same piece of information may be given multiple times, and multiple people may be at the same coordinates.



2025-04-18 (Fri)
17:00:53 +00:00