CF1766F.MCF
普及/提高-
通过率:0%
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?
输入格式
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.
输出格式
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.
输入输出样例
输入#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