Logo
(追記) (追記ここまで)

25892번 - Zero AAMP Currents 스페셜 저지다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 256 MB2617770.000%

문제

Thomas Edison stumbled upon an alien electrical device that appears to break known laws of physics! The device consists of $n$ batteries connected by $m$ unidirectional wires, which we will represent as vertices and edges that form a graph. The $i$-th wire is directed from battery $v_i$ to battery $u_i,ドル $v_i \ne u_i$. Let $(v_i → u_i)$ denote such a wire.

To make this device work, Thomas must assign a current strength to each wire such that this assignment results in a successful configuration. For a configuration to be successful, two conditions must be met:

  1. All current strength values are non-zero integers in the range $[-1000, 1000]$ AAMP (Alien Amperes).
  2. For every cycle found in this device, the sum of AAMP values from all wires in it must be 0ドル$. A cycle is a sequence of edges (wires) $(a_1 → a_2),ドル $(a_2 → a_3),ドル $\dots,ドル$(a_{k-1} → a_k),ドル $(a_k → a_1)$. If edges $(x → y)$ and $(y → x)$ both exist, they also form a cycle – the wires are unidirectional.

Help him with this task.

입력

The first line contains two integers $n$ and $m$ – the number of batteries and the number of wires in the device, respectively. Next, $m$ lines contain two integers each $v_i$ and $u_i,ドル which mean that the $i$-th wire goes from battery $v_i$ to $u_i$.

출력

Print $m$ lines containing one number each: the $i$-th number should be the current strength of $i$-th wire (in AAMP). Each number should be non-zero and in the range of $[-1000, 1000]$. If multiple answers exist, you may print any one of them.

제한

  • 1ドル ≤ n ≤ 10^5$
  • 1ドル ≤ m ≤ 2 \cdot 10^5$
  • 1ドル ≤ v_i , u_i ≤ n,ドル $v_i \ne u_i$

예제 입력 1

4 7
1 2
2 3
3 1
1 4
2 4
1 4
3 2

예제 출력 1

-1
-1
2
-2
-1
-2
1

노트

Note that there can be multiple wires from battery $x$ to $y$. Also note that wire $(x → y)$ with strength 3ドル$ AAMP is not the same as $(y → x)$ with strength $-3$. As mentioned before, wires are unidirectional and can have a negative current strength - that’s one of the mysteries of this device ...

출처

Contest > Waterloo's local Programming Contests > 2022 Waterloo Fall Local A번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /