아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Zero AAMP Currents

시간 제한2초메모리 제한256 MB

요약
모든 사이클을 따라 전류의 합이 0이 되도록 각 유향 간선에 [-1000, 1000] 범위의 0이 아닌 정수 전류를 배정한다.
난이도

보통10점 중 7점

유형
그래프, DFS, 수학
정답자
아직 제출이 없습니다

문제

Thomas Edison stumbled upon an alien electrical device that appears to break known laws of physics! The device consists of nn batteries connected by mm unidirectional wires, which we will represent as vertices and edges that form a graph. The ii-th wire is directed from battery v_iv\_i to battery u_iu\_i, v_i≠u_iv\_i \ne u\_i. Let (v_i→u_i)(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]\[-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 00. A cycle is a sequence of edges (wires) (a_1→a_2)(a\_1 → a\_2), (a_2→a_3)(a\_2 → a\_3), …\dots,(a_k−1→a_k)(a\_{k-1} → a\_k), (a_k→a_1)(a\_k → a\_1). If edges (x→y)(x → y) and (y→x)(y → x) both exist, they also form a cycle – the wires are unidirectional.

Help him with this task.

입력

The first line contains two integers nn and mm – the number of batteries and the number of wires in the device, respectively. Next, mm lines contain two integers each v_iv\_i and u_iu\_i, which mean that the ii-th wire goes from battery v_iv\_i to u_iu\_i.

출력

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

제한

  • 1≤n≤1051 ≤ n ≤ 10^5
  • 1≤m≤2⋅1051 ≤ m ≤ 2 \cdot 10^5
  • 1≤v_i,u_i≤n1 ≤ v\_i , u\_i ≤ n, v_i≠u_iv\_i \ne u\_i

힌트

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

예제1

  1. 예제 1

    입력
    4 7
    1 2
    2 3
    3 1
    1 4
    2 4
    1 4
    3 2
    
    예상 출력
    -1
    -1
    2
    -2
    -1
    -2
    1