BFS - 多源感染问题(LeetCode 994 腐烂橘子)
You cannot submit for this problem because the contest is ended. You can click "Open in Problem Set" to view this problem in normal mode.
题目描述
一个 n×m 网格,每个格子可能是:
0 空
1 新鲜橘子
2 腐烂橘子
每分钟腐烂橘子会向四邻域的新鲜橘子传播。求所有橘子腐烂所需最短分钟数,若无法全腐烂输出 -1。
输入格式
第一行 n, m 接下来 n 行,每行 m 个整数(0/1/2)
输出格式
一个整数,最短分钟数。
示例 输入:
3 3
2 1 1
1 1 0
0 1 1
输出
4
26年5月24日测评【深度搜索和广度搜索】
- Status
- Done
- Rule
- ACM/ICPC
- Problem
- 4
- Start at
- 2026-5-24 8:30
- End at
- 2026-5-24 18:30
- Duration
- 10 hour(s)
- Host
- Partic.
- 5