Assign a nonzero integer to each directed edge so every vertex's outgoing sum equals its incoming sum, exactly as built by a prescribed DFS cycle-circulation procedure.
Hard8GraphDFSImplementationSimulationNo attempts yetTime limit5sMemory limit512 MBYou want to get your F friends to share some news. You know your friends well, so you know which of them can talk to which. There are P one way relationships, and the i-th of them is an ordered pair (Ai,Bi) meaning that friend Ai can talk to friend Bi. It does not mean that friend Bi can talk to friend Ai, although another ordered pair may state that separately.
For every given ordered pair (Ai,Bi), friend Ai has to deliver one piece of news to friend Bi. A piece of news is one integer. Its absolute value is the magnitude of the news, and its sign gives the type of the news. The integer cannot be 0 (there would be no news at all), and its absolute value cannot exceed F2 (the news would be too exciting). Different ordered pairs may get different integers.
Because you care about your friends' feelings, for each friend the sum of the values of all news that friend delivers has to equal the sum of the values of all news that friend receives. If a friend delivers no news, that sum is 0. If a friend receives no news, that sum is 0.
Find a set of news values that obeys every rule, or determine that none exists.
The first line contains the number of test cases T. T test cases follow. The first line of each test case contains two integers F and P, the number of friends and the number of ordered pairs of friends. Each of the next P lines contains two different integers Ai and Bi, meaning that friend Ai can talk to friend Bi. Friends are numbered from 1 to F.
Limits
For each test case, print one line containing Case #x: y, where x is the test case number starting from 1 and y is one of the following.
If no assignment obeys the rules, y is IMPOSSIBLE.
Otherwise y is P integers separated by single spaces, and the i-th of them is the news value that friend Ai delivers to friend Bi. Many assignments obey the rules, so print exactly the one that this procedure builds.
Whenever an assignment that obeys the rules exists, the values this procedure builds are nonzero and lie inside [−F2,F2].
A friend who neither delivers nor receives any news still obeys the rules.
If some friend only receives news and can talk to nobody, the test case is IMPOSSIBLE. A news value cannot be 0, so the sum received is nonzero while the sum delivered is 0.
A value whose absolute value exceeds F2 is not allowed even when every other rule holds.
Some test cases cannot be solved without at least one negative value.