#abc320d. D - Relative Position

D - Relative Position

Score : 400400 points

问题描述

在坐标平面上有 NN 名编号为 11NN 的人。
11 号人在原点。

给定 MM 条如下形式的信息:

  • 从第 AiA_i 号人的视角看,第 BiB_i 号人在正 xx 轴方向上距离为 XiX_i 单位,在正 yy 轴方向上距离为 YiY_i 单位。

请确定每个人所在的坐标。如果某个人的坐标无法唯一确定,请报告这一事实。

以上为通义千问 qwen-max 翻译,仅供参考。

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 1

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

Sample Output 1

0 0
2 1
-1 -2

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

Figure

Sample Input 2

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

Sample Output 2

0 0
2 1
-1 -2

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

Figure

Sample Input 3

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 3

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.

update @ 2024/3/10 01:38:41