#P13942. [EC Final 2019] Flow

[EC Final 2019] Flow

题目描述

One of Pang\textit{Pang}'s research interests is the maximum flow problem.

A directed graph GG with nn vertices is universe\textit{universe} if the following condition is satisfied:

  • GG is the union of kk vertex-independent simple paths from vertex 11 to vertex nn of the same length.

A set of paths is vertex-independent if they do not have any internal vertex in common.

A vertex in a path is called internal if it is not an endpoint of that path.

A path is simple if its vertices are distinct.

Let GG be a universe\textit{universe} graph with nn vertices and mm edges. Each edge has a non-negative integral capacity. You are allowed to perform the following operation any (including 00) times to make the maximum flow from vertex 11 to vertex nn as large as possible:

Let ee be an edge with positive capacity. Reduce the capacity of ee by 11 and increase the capacity of another edge by 11.

Pang\textit{Pang} wants to know what is the minimum number of operations to achieve it?

输入格式

The first line contains two integers nn and mm (2n100000,1m2000002\leq n\leq 100000, 1\leq m \leq 200000).

Each of the next mm lines contains three integers x,yx, y and zz, denoting an edge from xx to yy with capacity zz (1x,yn1 \leq x, y \leq n, 0z10000000000\le z\le 1000000000).

It's guaranteed that the input is a universeuniverse graph without multiple edges and self-loops.

输出格式

Output a single integer --- the minimum number of operations.

4 3
1 2 1
2 3 2
3 4 3
1
4 4
1 2 1
1 3 1
2 4 2
3 4 2
1