No tags yet

No tag edit access

time limit per test: 0.5 sec.

memory limit per test: 4096 KB

memory limit per test: 4096 KB

input: standard

output: standard

output: standard

You have given the net consisting of nodes and pipes; pipes connect the nodes. Some substance can flow by pipes, and flow speed in any pipe doesn't exceed capacity of this pipe.

The substance cannot be accumulated in the nodes. But it is being produced in the first node with the non-negative speed and being consumed with the same speed in the last node.

You have some subset taken from the set of pipes of this net. You need to start the motion of substance in the net, and your motion must fully fill the pipes of the given subset. Speed of the producing substance in the first node must be minimal.

Calculate this speed and show the scene of substance motion.

Remember that substance can't be accumulated in the nodes of the net.

The substance cannot be accumulated in the nodes. But it is being produced in the first node with the non-negative speed and being consumed with the same speed in the last node.

You have some subset taken from the set of pipes of this net. You need to start the motion of substance in the net, and your motion must fully fill the pipes of the given subset. Speed of the producing substance in the first node must be minimal.

Calculate this speed and show the scene of substance motion.

Remember that substance can't be accumulated in the nodes of the net.

Two positive integer numbers N (1<=N<=100) and M have been written in the first line of the input - numbers of nodes and pipes.

There are M lines follows: each line contains four integer numbers Ui, Vi, Zi, Ci; the numbers are separated by a space. Ui is the beginning of i-th pipe, Vi is its end, Zi is a capacity of i-th pipe (1<=Zi<=10^5) and Ci is 1 if i-th pipe must be fully filled, and 0 otherwise.

Any pair of nodes can be connected only by one pipe. If there is a pipe from node A to node B, then there is no pipe from B to A. Not a single node is connected with itself.

There is no pipe which connects nodes number 1 and N. Substance can flow only from the beginning of a pipe to its end.

There are M lines follows: each line contains four integer numbers Ui, Vi, Zi, Ci; the numbers are separated by a space. Ui is the beginning of i-th pipe, Vi is its end, Zi is a capacity of i-th pipe (1<=Zi<=10^5) and Ci is 1 if i-th pipe must be fully filled, and 0 otherwise.

Any pair of nodes can be connected only by one pipe. If there is a pipe from node A to node B, then there is no pipe from B to A. Not a single node is connected with itself.

There is no pipe which connects nodes number 1 and N. Substance can flow only from the beginning of a pipe to its end.

Write one integer number in the first line of the output - it ought to be the minimal speed of the producing substance in the first node.

Write M integers in the second line - i-th number ought to be the flow speed in the i-th pipe (numbering of pipes is equal to the input).

If it is impossible to fill the given subset, write "Impossible".

Write M integers in the second line - i-th number ought to be the flow speed in the i-th pipe (numbering of pipes is equal to the input).

If it is impossible to fill the given subset, write "Impossible".

Input

Input 1:

4 4

1 2 2 0

2 4 1 1

1 3 2 1

3 4 3 0

Input 2:

4 4

1 2 1 0

2 4 2 1

1 3 3 1

3 4 2 0

4 4

1 2 2 0

2 4 1 1

1 3 2 1

3 4 3 0

Input 2:

4 4

1 2 1 0

2 4 2 1

1 3 3 1

3 4 2 0

Output

Output 1:

3

1 1 2 2

Output 2:

Impossible

3

1 1 2 2

Output 2:

Impossible

Author: | Dmitry Orlov |

Resource: | Saratov ST team Spring Contest #1 |

Date: | 18.05.2003 |

Codeforces (c) Copyright 2010-2020 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Sep/23/2020 10:42:50 (h2).

Desktop version, switch to mobile version.

Supported by

User lists

Name |
---|