CF362E.Petya and Pipes

提高+/省选-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

A little boy Petya dreams of growing up and becoming the Head Berland Plumber. He is thinking of the problems he will have to solve in the future. Unfortunately, Petya is too inexperienced, so you are about to solve one of such problems for Petya, the one he's the most interested in.

The Berland capital has n water tanks numbered from 1 to n. These tanks are connected by unidirectional pipes in some manner. Any pair of water tanks is connected by at most one pipe in each direction. Each pipe has a strictly positive integer width. Width determines the number of liters of water per a unit of time this pipe can transport. The water goes to the city from the main water tank (its number is 1). The water must go through some pipe path and get to the sewer tank with cleaning system (its number is n).

Petya wants to increase the width of some subset of pipes by at most k units in total so that the width of each pipe remains integer. Help him determine the maximum amount of water that can be transmitted per a unit of time from the main tank to the sewer tank after such operation is completed.

一个小男孩佩佳梦想着快快长大,成为贝尔兰首席管道工。他正在思考自己将来需要解决的问题。然而,佩佳目前经验尚浅,因此你将替他解决其中一道他最感兴趣的问题。

贝尔兰首都共有 nn 个水箱,编号从 11 到 nn。这些水箱以某种方式通过有向管道相互连接。任意两个水箱之间在每个方向上至多只有一条管道。每条管道具有一个严格正整数宽度;该宽度表示单位时间内该管道所能输送的水量(单位:升)。城市用水来自主水箱(编号为 11),水流需经由某条有向路径最终到达污水处理水箱(编号为 nn),该水箱配备净化系统。

佩佳希望将某一部分管道的宽度总共最多增加 kk 个单位(每次增加量为非负整数),使得每条管道的宽度仍为整数。请你帮助他确定:完成该操作后,单位时间内能从主水箱输送到污水处理水箱的最大水量是多少?

输入格式

The first line contains two space-separated integers n and k (2 ≤ n ≤ 50, 0 ≤ k ≤ 1000). Then follow n lines, each line contains n integers separated by single spaces. The i + 1-th row and j-th column contain number c__ij — the width of the pipe that goes from tank i to tank j (0 ≤ c__ij ≤ 106, c__ii = 0). If c__ij = 0, then there is no pipe from tank i to tank j.

第一行包含两个以空格分隔的整数 nn 和 kk(2≤n≤502 \leq n \leq 50,0≤k≤10000 \leq k \leq 1000)。接下来是 nn 行,每行包含 nn 个以单个空格分隔的整数。第 i+1i+1 行、第 jj 列的数为 cijc_{ij} —— 表示从水箱 ii 流向水箱 jj 的管道的容量(0≤cij≤1060 \leq c_{ij} \leq 10^6,且 cii=0c_{ii} = 0)。若 cij=0c_{ij} = 0,则表示不存在从水箱 ii 到水箱 jj 的管道。

输出格式

Print a single integer — the maximum amount of water that can be transmitted from the main tank to the sewer tank per a unit of time.

输出一个整数——单位时间内从主水箱传输到污水水箱的最大水量。

输入输出样例

  • 输入#1

    5 7
    0 1 0 2 0
    0 0 4 10 0
    0 0 0 0 5
    0 0 0 0 10
    0 0 0 0 0

    输出#1

    10
  • 输入#2

    5 10
    0 1 0 0 0
    0 0 2 0 0
    0 0 0 3 0
    0 0 0 0 4
    100 0 0 0 0

    输出#2

    5

说明/提示

In the first test Petya can increase width of the pipe that goes from the 1st to the 2nd water tank by 7 units.

In the second test Petya can increase width of the pipe that goes from the 1st to the 2nd water tank by 4 units, from the 2nd to the 3rd water tank by 3 units, from the 3rd to the 4th water tank by 2 units and from the 4th to 5th water tank by 1 unit.

在第一个测试中,Petya 可以将从第 1 个水箱流向第 2 个水箱的管道宽度增加 7 个单位。

在第二个测试中,Petya 可以将从第 1 个水箱流向第 2 个水箱的管道宽度增加 4 个单位,从第 2 个水箱流向第 3 个水箱的管道宽度增加 3 个单位,从第 3 个水箱流向第 4 个水箱的管道宽度增加 2 个单位,以及从第 4 个水箱流向第 5 个水箱的管道宽度增加 1 个单位。

输入解题思路,AI测评打分。不知道怎么写?

首页