I wonder if it's irrelevant to use BFS!

Asked 1 years ago, Updated 1 years ago, 432 views

The questions are as follows!

https://velog.velcdn.com/images/suzieep/post/3b7def0f-629d-47bb-9214-5accef563230/image.png

There is an ice mold of N×M size. The part with the hole is marked as 0 and the part with the partition is marked as 1.

If the perforated parts are attached up, down, left, and right, they are considered to be connected to each other.

Write a program to determine the total number of ice creams produced when given the shape of the ice mold.

In the following 4×5 ice mold example, a total of 3 ice creams are produced.

Here, the book visits all indexes, runs DFS, and counts the number of zones.

I used BFS because I thought it doesn't matter whether it's BFS or DFS because it's a matter of dividing the area.

I'm asking if there's an unexpected counterex May I know if it is irrelevant to use BFS instead of DFS in that matter?

algorithm coding-test bfs

2023-03-03 15:20

1 Answers

(You're counting the number of zeros that are connected anyway. It doesn't matter if you use BFS. Try to solve both and compare them.


2023-03-03 16:32

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.