2022 Fall Waterloo Local Contest, Problem A
Thomas Edison stumbled upon an alien electrical device that appears to break known laws of physics!
The device consists of batteries connected by
unidirectional wires, which we will represent as vertices
and edges that form a graph. The
wire is directed from battery
to battery
,
. Let
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:
- All current strength values are non-zero integers in the range
AAMP (Alien Amperes).
- For every cycle found in this device, the sum of AAMP values from all wires in it must be
. A cycle is a sequence of edges (wires)
. If edges
and
both exist, they also form a cycle - the wires are unidirectional.
Help him with this task.
Constraints
Input Specification
The first line contains two integers and
- the number of batteries and the number of wires in the
device, respectively. Next,
lines contain two integers each
and
, which mean that the
wire goes
from battery
to
.
Output Specification
Print lines containing one number each: the
number should be the current strength of
wire (in
AAMP). Each number should be non-zero and in the range of
. If multiple answers exist,
you may print any one of them.
Sample Input
4 7
1 2
2 3
3 1
1 4
2 4
1 4
3 2
Sample Output
-1
-1
2
-2
-1
-2
1
Note
Note that there can be multiple wires from battery to
. Also note that wire
with strength
AAMP is not the same as
with strength
. As mentioned before, wires are unidirectional and
can have a negative current strength - that's one of the mysteries of this device…
Comments