#P3866. [TJOI2009] 战争游戏

    ID: 2802 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>2009各省省选最大流最小割天津

[TJOI2009] 战争游戏

Description

Before the enemies start moving, your task is to use airstrikes to turn some originally empty cells into impassable cells, which may prevent the enemies from leaving the map. For special reasons, you cannot bomb any cell currently occupied by an enemy unit. Due to terrain differences, the amount of explosives needed to bomb each empty cell into an impassable cell may vary. You need to compute the minimum total amount of explosives required to prevent the enemies from moving out of the map boundary.

Input Format

The first line contains two integers MM and NN, the numbers of rows and columns of the grid. The next MM lines each contain NN space-separated integers, describing the grid cells:

  • If the number is 1-1, the cell is an obstacle.
  • If the number is 00, there is an enemy unit in this cell.
  • If the number is a positive integer xx, the cell is empty, and xx units of explosives are needed to bomb it into an impassable cell.

The number of enemy units on the map is not equal to 11 (i.e., there are at least two cells with 00).

Output Format

Output a single number: the minimum total amount of explosives required. The testdata guarantee that a solution exists.

4 3
1 2 1
1 10 1
1 0 -1
1 1 1
6

Hint

  • For 50% of the testdata, 1M,N101 \le M, N \le 10.
  • For 100% of the testdata, 1M,N301 \le M, N \le 30.
  • Every number in the matrix does not exceed 100100.

Translated by ChatGPT 5