#P9902. 『PG2』模拟最大流

『PG2』模拟最大流

Problem Description

Given nn nodes and mm directed edges, each edge has a capacity. It is guaranteed that every edge (u,v,w)(u,v,w) satisfies vu[0,k]v-u\in[0,k]. Find the maximum flow from node 11 to node nn.

Input Format

The first line contains three positive integers nn, mm, and kk, separated by spaces.

The next mm lines each contain three positive integers uiu_i, viv_i, and wiw_i, separated by spaces, meaning that the ii-th directed edge starts from uiu_i, ends at viv_i, and has capacity wiw_i.

Output Format

Output one integer, the maximum flow from 11 to nn.

9 21 3
1 2 1
2 3 1
3 4 1
4 5 1
5 6 1
6 7 1
7 8 1
8 9 1
1 3 1
2 4 1
3 5 1
4 6 1
5 7 1
6 8 1
7 9 1
1 4 1
2 5 1
3 6 1
4 7 1
5 8 1
6 9 1
3
5 10 2
3 5 73
3 4 33
3 5 84
4 5 10
3 4 15
1 2 83
1 3 8
1 3 24
5 5 15
1 2 62
32

Hint

For 20%20\% of the testdata, n102n\leq 10^2, m104m\leq 10^4, k2k\leq 2.

For 40%40\% of the testdata, n104n\leq 10^4, m106m\leq 10^6, k2k\leq 2.

For 60%60\% of the testdata, n8×104n\leq 8\times 10^4, m106m\leq 10^6, k2k\leq 2.

For 80%80\% of the testdata, n8×104n\leq 8\times 10^4, m106m\leq 10^6, k4k\leq 4.

For 100%100\% of the testdata, 2n8×1042\leq n\leq 8\times 10^4, 1m1061\leq m\leq 10^6, 2k72\leq k\leq 7, 1w1001\leq w\leq 100.

Translated by ChatGPT 5