303665: CF708D. Incorrect Flow
Memory Limit:256 MB
Time Limit:1 S
Judge Style:Text Compare
Creator:
Submit:0
Solved:0
Description
Incorrect Flow
题意翻译
- 给定一张 $n$ 个点 $m$ 条边的网络,源点为 $1$,汇点为 $n$。 - 对于每条边,有容量 $c$,当前流量 $f$。 - 但这个图是错误的,可能存在 $c < f$,或者流量不守恒的情况。 - 你每次操作可以将某条边的 $c$ 或 $f$ 加 $1$ 或减 $1$。 - 请你用最少的操作次数将图变成一个正确的网络。 - $n,m \le 100$,$c,f \le 10^6$,$1$ 没有入边,$n$ 没有出边。题目描述
At the entrance examination for the magistracy of the MSU Cyber-Mechanics Department Sasha got the question about Ford-Fulkerson algorithm. He knew the topic perfectly as he worked with it many times on programming competition. As the task for the question he was given a network with partially build flow that he had to use in order to demonstrate the workflow of the algorithm. He quickly finished to write the text and took a look at the problem only to understand that the given network is incorrect! Suppose you are given a directed graph $ G(V,E) $ with two special nodes $ s $ and $ t $ called source and sink. We denote as $ n $ the number of nodes in the graph, i.e. $ n=|V| $ and $ m $ stands for the number of directed edges in the graph, i.e. $ m=|E| $ . For the purpose of this problem we always consider node $ 1 $ to be the source and node $ n $ to be the sink. In addition, for each edge of the graph $ e $ we define the capacity function $ c(e) $ and flow function $ f(e) $ . Function $ f(e) $ represents the correct flow if the following conditions are satisfied: 1. For each edge ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF708D/a585d8d95c9513db733035d06d3770f5949603f7.png) the flow is non-negative and does not exceed capacity $ c(e) $ , i.e. $ 0<=f(e)<=c(e) $ . 2. For each node ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF708D/3fe63339e2f1d1727b2811405afd4d24d70f444c.png), that is not source or sink ( $ v≠s $ and $ v≠t $ ) the sum of flows of all edges going in $ v $ is equal to the sum of the flows among all edges going out from $ v $ . In other words, there is no flow stuck in $ v $ . It was clear that as the exam was prepared last night and there are plenty of mistakes in the tasks. Sasha asked one of the professors to fix the network or give the correct task, but the reply was that the magistrate student should be able to fix the network himself. As the professor doesn't want the task to become easier, he asks Sasha to fix the network in a such way that the total number of changes is minimum possible. Sasha is not allowed to remove edges, add new ones or reverse the direction of existing edges. The only thing he is able to do is to change capacity function $ c(e) $ and flow function $ f(e) $ . Moreover, all the values should remain non-negative integers. There is no requirement on the flow to be maximum in any sense. Find the minimum possible total change of the functions $ f(e) $ and $ c(e) $ that Sasha has to make in order to make the flow correct. The total change is defined as the sum of absolute differences, i.e. if new functions are $ f^{*}(e) $ and $ c^{*}(e) $ , then the total change is ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF708D/58e27a22767c3ecfc23522dd629387e236285247.png).输入输出格式
输入格式
The first line of the input contains two integers $ n $ and $ m $ ( $ 2<=n<=100 $ , $ 0<=m<=100 $ ) — the number of nodes and edges in the graph respectively. Each of the following $ m $ lines contains the description of the edges, consisting of four integers $ u_{i} $ , $ v_{i} $ , $ c_{i} $ and $ f_{i} $ ( $ 1<=u_{i},v_{i}<=n $ , $ u_{i}≠v_{i} $ , $ 0<=c_{i},f_{i}<=1000000 $ ) — index of the node the edges starts from, the index of the node the edge goes to, current capacity and flow value. Node number $ 1 $ is the source, and node number $ n $ is the sink. It's guaranteed that no edge goes to the source, and no edges starts in the sink. Given graph contains no self-loops but may contain multiple edges.
输出格式
Print one integer — the minimum total sum of changes that Sasha has to do in order to get the correct flow description.
输入输出样例
输入样例 #1
2 1
1 2 2 1
输出样例 #1
0
输入样例 #2
2 1
1 2 1 2
输出样例 #2
1
输入样例 #3
3 3
1 2 1 1
2 3 2 2
1 3 3 3
输出样例 #3
1
输入样例 #4
4 2
2 3 1 1
3 2 1 1
输出样例 #4
0