# CodeForces - 708D Incorrect Flow

### Description

$n,m\le 100,0\le c,f\le 10^6$

### Solution

• $d[u]-=f,d[v]+=f$

• $f > c$
• $(v, u, f - c,0)$
• $(v,u,c,1)$
• $(u,v,\inf,2)$
• $ans +=f-c$
• $f\le c$
• $(v,u,f,1)$
• $(u,v,c-f,1)$
• $(u,v,inf,2)$

#include<bits/stdc++.h>
using namespace std;

template <class T> void read(T &x) {
x = 0; bool flag = 0; char ch = getchar(); for (; ch < '0' || ch > '9'; ch = getchar()) flag |= ch == '-';
for (; ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - 48; flag ? x = ~x + 1 : 0;
}

#define N 110
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define INF 0x3f3f3f3f

int S, T, flow, cost, head[N], tot = 1, dis[N], pre[N];
struct { int v, c, w, next; }e[100001];
queue<int> q;
bool inq[N];
inline void insert(int u, int v, int c, int w) {
e[++tot].v = v, e[tot].c = c, e[tot].w = w, e[tot].next = head[u], head[u] = tot;
}
inline void add(int u, int v, int c, int w) {
insert(u, v, c, w), insert(v, u, 0, -w);
}
bool spfa() {
memset(dis, 0x3f, sizeof dis); dis[S] = 0, q.push(S);
while (!q.empty()) {
int u = q.front(); q.pop(), inq[u] = 0;
for (int i = head[u], v; i; i = e[i].next) e[i].c && dis[v = e[i].v] > dis[u] + e[i].w ?
dis[v] = dis[u] + e[i].w, pre[v] = i, (!inq[v] ? q.push(v), inq[v] = 1 : 0) : 0;
}
return dis[T] < INF;
}
void mcf() {
int d = INF;
for (int i = T; i != S; i = e[pre[i] ^ 1].v) d = min(d, e[pre[i]].c);
for (int i = T; i != S; i = e[pre[i] ^ 1].v) e[pre[i]].c -= d, e[pre[i] ^ 1].c += d, cost += d * e[pre[i]].w;
flow += d;
}

int d[N];

int main() {
T = n + 1;
int ans = 0;
rep(i, 1, m) {
d[u] -= f, d[v] += f;
}