CF1766F.MCF

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given a graph consisting of nn vertices and mm directed arcs. The ii -th arc goes from the vertex xix_i to the vertex yiy_i , has capacity cic_i and weight wiw_i . No arc goes into the vertex 11 , and no arc goes from the vertex nn . There are no cycles of negative weight in the graph (it is impossible to travel from any vertex to itself in such a way that the total weight of all arcs you go through is negative).

You have to assign each arc a flow (an integer between 00 and its capacity, inclusive). For every vertex except 11 and nn , the total flow on the arcs going to this vertex must be equal to the total flow on the arcs going from that vertex. Let the flow on the ii -th arc be fif_i , then the cost of the flow is equal to i=1mfiwi\sum \limits_{i = 1}^{m} f_i w_i . You have to find a flow which minimizes the cost.

Sounds classical, right? Well, we have some additional constraints on the flow on every edge:

  • if cic_i is even, fif_i must be even;
  • if cic_i is odd, fif_i must be odd.

Can you solve this problem?

输入格式

The first line contains two integers nn and mm ( 2n1002 \le n \le 100 ; 1m2001 \le m \le 200 ).

Then mm lines follow. The ii -th of them contains four integers xix_i , yiy_i , cic_i , and wiw_i ( 1xin11 \le x_i \le n - 1 ; 2yin2 \le y_i \le n ; xiyix_i \ne y_i ; 1ci1001 \le c_i \le 100 ; 100wi100-100 \le w_i \le 100 ). These integers describe the ii -th arc.

Additional constraints on the input:

  • there are no negative cycles in the graph.

输出格式

If a flow satisfying all of the constraints does not exist, print Impossible.

Otherwise, print two lines:

  • the first line should contain one word Possible;
  • the second line should contain mm integers f1,f2,,fmf_1, f_2, \dots, f_m .

If there are multiple answers, print any of them. Note that the cost of the flow should be minimized.

输入输出样例

  • 输入#1

    3 3
    1 2 3 -10
    1 2 3 -15
    2 3 2 0

    输出#1

    Possible
    1 1 2
  • 输入#2

    3 3
    1 2 3 -10
    1 2 3 -15
    2 3 3 0

    输出#2

    Impossible
  • 输入#3

    3 3
    1 2 3 -10
    1 2 3 -15
    2 3 4 0

    输出#3

    Possible
    1 3 4
  • 输入#4

    6 7
    5 6 9 -40
    1 2 3 -10
    1 4 5 20
    4 5 7 30
    2 5 1 -15
    1 3 3 5
    3 5 3 0

    输出#4

    Possible
    5 1 1 1 1 3 3
首页