CF1766F.MCF
省选/NOI-
通过率:0%
时间限制:4.00s
内存限制:512MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given a graph consisting of n vertices and m directed arcs. The i-th arc goes from the vertex xi to the vertex yi, has capacity ci and weight wi. No arc goes into the vertex 1, and no arc goes from the vertex n. 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 0 and its capacity, inclusive). For every vertex except 1 and n, 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 i-th arc be fi, then the cost of the flow is equal to i=1∑mfiwi. 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 ci is even, fi must be even;
- if ci is odd, fi must be odd.
Can you solve this problem?
你被给定一个包含 n 个顶点和 m 条有向边的图。第 i 条边从顶点 xi 指向顶点 yi,其容量为 ci、权重为 wi。没有任何边指向顶点 1,也没有任何边从顶点 n 出发。图中不存在负权环(即:无法从任意顶点出发,经过若干条边后回到自身,且所经过所有边的总权重为负)。
你需要为每条边分配一个流量(一个介于 0 与该边容量(含端点)之间的整数)。对于除顶点 1 和顶点 n 外的每个顶点,流入该顶点的所有边的流量之和必须等于流出该顶点的所有边的流量之和。设第 i 条边上的流量为 fi,则该流的费用定义为 i=1∑mfiwi。你需要找出一个使总费用最小的可行流。
听起来很经典,对吧?不过,我们对每条边上的流量还有额外的约束:
- 若 ci 为偶数,则 fi 必须为偶数;
- 若 ci 为奇数,则 fi 必须为奇数。
你能解决这个问题吗?
输入格式
The first line contains two integers n and m (2≤n≤100; 1≤m≤200).
Then m lines follow. The i-th of them contains four integers xi, yi, ci, and wi (1≤xi≤n−1; 2≤yi≤n; xi=yi; 1≤ci≤100; −100≤wi≤100). These integers describe the i-th arc.
Additional constraints on the input:
- there are no negative cycles in the graph.
第一行包含两个整数 n 和 m(2≤n≤100;1≤m≤200)。
接下来是 m 行。其中第 i 行包含四个整数 xi、yi、ci 和 wi(1≤xi≤n−1;2≤yi≤n;xi=yi;1≤ci≤100;−100≤wi≤100)。这些整数描述第 i 条有向边。
输入的额外约束条件:
- 图中不存在负权环。
输出格式
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 m integers f1,f2,…,fm.
If there are multiple answers, print any of them. Note that the cost of the flow should be minimized.
如果不存在满足所有约束条件的流,则输出 Impossible。
否则,输出两行:
- 第一行输出一个单词
Possible; - 第二行输出 m 个整数 f1,f2,…,fm。
若存在多个解,输出任意一个即可。注意:该流的费用应最小化。
输入输出样例
输入#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测评打分。不知道怎么写?