CF1766F.MCF

省选/NOI-

通过率:0%

时间限制:4.00s

内存限制:512MB

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?

你被给定一个包含 nn 个顶点和 mm 条有向边的图。第 ii 条边从顶点 xix_i 指向顶点 yiy_i,其容量为 cic_i、权重为 wiw_i。没有任何边指向顶点 11,也没有任何边从顶点 nn 出发。图中不存在负权环(即:无法从任意顶点出发,经过若干条边后回到自身,且所经过所有边的总权重为负)。

你需要为每条边分配一个流量(一个介于 00 与该边容量(含端点)之间的整数)。对于除顶点 11 和顶点 nn 外的每个顶点,流入该顶点的所有边的流量之和必须等于流出该顶点的所有边的流量之和。设第 ii 条边上的流量为 fif_i,则该流的费用定义为 ∑i=1mfiwi\sum \limits_{i = 1}^{m} f_i w_i。你需要找出一个使总费用最小的可行流。

听起来很经典,对吧?不过,我们对每条边上的流量还有额外的约束:

  • 若 cic_i 为偶数,则 fif_i 必须为偶数;
  • 若 cic_i 为奇数,则 fif_i 必须为奇数。

你能解决这个问题吗?

输入格式

The first line contains two integers nn and mm (2≤n≤1002 \le n \le 100; 1≤m≤2001 \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 (1≤xi≤n−11 \le x_i \le n - 1; 2≤yi≤n2 \le y_i \le n; xi≠yix_i \ne y_i; 1≤ci≤1001 \le c_i \le 100; −100≤wi≤100-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.

第一行包含两个整数 nn 和 mm(2≤n≤1002 \le n \le 100;1≤m≤2001 \le m \le 200)。

接下来是 mm 行。其中第 ii 行包含四个整数 xix_i、yiy_i、cic_i 和 wiw_i(1≤xi≤n−11 \le x_i \le n - 1;2≤yi≤n2 \le y_i \le n;xi≠yix_i \ne y_i;1≤ci≤1001 \le c_i \le 100;−100≤wi≤100-100 \le w_i \le 100)。这些整数描述第 ii 条有向边。

输入的额外约束条件:

  • 图中不存在负权环。

输出格式

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.

如果不存在满足所有约束条件的流,则输出 Impossible。

否则,输出两行:

  • 第一行输出一个单词 Possible;
  • 第二行输出 mm 个整数 f1,f2,…,fmf_1, f_2, \dots, f_m。

若存在多个解,输出任意一个即可。注意:该流的费用应最小化。

输入输出样例

  • 输入#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

输入解题思路,AI测评打分。不知道怎么写?

首页