2025-10-13 21:52:44 -04:00
|
|
|
"""
|
|
|
|
|
name: Nicholas Tamassia
|
|
|
|
|
|
|
|
|
|
Honor Code and Acknowledgments:
|
|
|
|
|
|
|
|
|
|
This work complies with the JMU Honor Code.
|
|
|
|
|
|
|
|
|
|
Comments here on your code and submission.
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
2025-10-14 18:12:39 -04:00
|
|
|
def explore_island(grid: list[list[int]], start: tuple[int, int]) -> int:
|
|
|
|
|
num_rows: int = len(grid)
|
|
|
|
|
num_cols: int = len(grid[0])
|
2025-10-14 08:20:28 -04:00
|
|
|
size: int = 0
|
|
|
|
|
|
|
|
|
|
def recurse(coord: tuple[int, int]):
|
|
|
|
|
x, y = coord
|
|
|
|
|
|
2025-10-14 18:12:39 -04:00
|
|
|
if grid[y][x] == 0:
|
2025-10-14 08:20:28 -04:00
|
|
|
return
|
|
|
|
|
|
|
|
|
|
nonlocal size
|
|
|
|
|
size += 1
|
2025-10-14 18:12:39 -04:00
|
|
|
grid[y][x] = 0
|
2025-10-14 08:20:28 -04:00
|
|
|
|
|
|
|
|
if y > 0:
|
2025-10-14 18:12:39 -04:00
|
|
|
recurse((x, y - 1))
|
2025-10-14 09:41:47 -04:00
|
|
|
if y < num_rows - 1:
|
2025-10-14 18:12:39 -04:00
|
|
|
recurse((x, y + 1))
|
2025-10-14 08:20:28 -04:00
|
|
|
if x > 0:
|
2025-10-14 18:12:39 -04:00
|
|
|
recurse((x - 1, y))
|
2025-10-14 09:41:47 -04:00
|
|
|
if x < num_cols - 1:
|
2025-10-14 18:12:39 -04:00
|
|
|
recurse((x + 1, y))
|
2025-10-14 08:20:28 -04:00
|
|
|
|
|
|
|
|
recurse(start)
|
|
|
|
|
|
|
|
|
|
return size
|
|
|
|
|
|
|
|
|
|
|
2025-10-13 21:52:44 -04:00
|
|
|
# All modules for CS 412 must include a main method that allows it
|
|
|
|
|
# to imported and invoked from other python scripts
|
|
|
|
|
def main():
|
|
|
|
|
n: int = int(input())
|
|
|
|
|
|
2025-10-14 18:12:39 -04:00
|
|
|
land_grid: list[list[int]] = [list(map(int, input().split())) for _ in range(0, n)]
|
2025-10-14 09:41:47 -04:00
|
|
|
|
2025-10-14 18:12:39 -04:00
|
|
|
num_rows: int = n
|
|
|
|
|
num_cols: int = len(land_grid[0])
|
2025-10-13 21:52:44 -04:00
|
|
|
|
2025-10-14 08:20:28 -04:00
|
|
|
largest_island: int = -1
|
|
|
|
|
|
2025-10-14 09:41:47 -04:00
|
|
|
for y in range(0, num_rows):
|
|
|
|
|
for x in range(0, num_cols):
|
2025-10-14 18:12:39 -04:00
|
|
|
if land_grid[y][x] == 0:
|
2025-10-14 08:20:28 -04:00
|
|
|
continue
|
|
|
|
|
|
2025-10-14 09:41:47 -04:00
|
|
|
island_size: int = explore_island(land_grid, (x, y))
|
2025-10-14 08:20:28 -04:00
|
|
|
|
|
|
|
|
if island_size > largest_island:
|
|
|
|
|
largest_island = island_size
|
|
|
|
|
|
|
|
|
|
print(largest_island)
|
2025-10-13 21:52:44 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
main()
|