#P4214. [CERC2015] Juice Junctions

[CERC2015] Juice Junctions

Description

You are hired to upgrade an old juice factory’s orange juice transport system. The system consists of pipes and nodes. Each pipe is bidirectional, and each pipe has a flow rate of 11 liter per second. Pipes connect nodes, and each node can be connected to at most 33 pipes. Nodes have infinite capacity. Nodes are labeled by integers 11 through nn. Before the upgrade, you need to analyze the existing system. For two distinct nodes ss and tt, the sstt flow is defined as the maximum flow from ss to tt when ss is the source and tt is the sink.

In the first sample below, the flow from 11 to 66 is 33, and the flow from 11 to 22 is 22.

Compute the sum of aabb flows over all pairs of nodes with a<ba < b.

Input Format

The first line contains 22 integers nn and mm (2n3×1032\leq n\leq 3\times 10^3, 0m45000\leq m\leq 4500), denoting the number of nodes and the number of pipes.

Each of the next mm lines contains two distinct integers a,ba,b (1a,bn1\leq a,b\leq n), indicating that there is a pipe connecting nodes aa and bb.

Each node is incident to at most 33 pipes, and there is at most one pipe between any pair of nodes.

Output Format

Output a single integer: the sum of aabb flows over all pairs with a<ba<b.

6 8
1 3
2 3
4 1
5 6
2 6
5 1
6 4
5 3
36

Hint

Translated by ChatGPT 5