Problem: Takahashi has a maze, which is a grid of H \times W squares with H horizontal rows and W vertical columns.  The square at the i-th row from the top and the j-th column is a "wall" square if S_{ij} is `#`, and a "road" square if S_{ij} is `.`.  From a road square, you can move to a horizontally or vertically adjacent road square.  You cannot move out of the maze, move to a wall square, or move diagonally.  Takahashi will choose a starting square and a goal square, which can be any road squares, and give the maze to Aoki.  Aoki will then travel from the starting square to the goal square, in the minimum number of moves required.  In this situation, find the maximum possible number of moves Aoki has to make.

Submission attempts (in order):
row,col=map(int,input().split())
maze=[list(input()) for _ in range(row)]
result = []
 
def create_next_adj_list(point):
  cur_x, cur_y, cur_depth = point
  return [(cur_x, cur_y+1, cur_depth+1), (cur_x+1, cur_y, cur_depth+1), (cur_x, cur_y-1, cur_depth+1), (cur_x-1, cur_y, cur_depth+1)]
 
for r in range(row):
  for c in range(col):
 
    visited = [ [0]*col for _ in range(row)]
    visited[r][c] = -1
 
    adj_list = [(r, c+1, 0), (r+1, c, 0), (r, c-1, 0), (r-1, c, 0)]
 
    while adj_list:
    # for p in range(len(adj_list)):
      max_depth = 0
      point = adj_list.pop(0)

      if 0<=point[0]<row and 0<=point[1]<col and visited[point[0]][point[1]] != -1:
        visited[point[0]][point[1]] = -1
        if maze[point[0]][point[1]] != '#':
          for adj in create_next_adj_list(point):
            adj_list.append(adj)
          if point[-1] > max_depth:
            max_depth = point[-1]

      result.append(max_depth)

print(max(result))

row,col=map(int,input().split())
maze=[list(input()) for _ in range(row)]
result = []
 
def create_next_adj_list(point):
  cur_x, cur_y, cur_depth = point
  return [(cur_x, cur_y+1, cur_depth+1), (cur_x+1, cur_y, cur_depth+1), (cur_x, cur_y-1, cur_depth+1), (cur_x-1, cur_y, cur_depth+1)]
 
for r in range(row):
  for c in range(col):
 
    visited = [ [0]*col for _ in range(row)]
    visited[r][c] = -1
 
    adj_list = [(r, c+1, 0), (r+1, c, 0), (r, c-1, 0), (r-1, c, 0)]
 
    while adj_list:
    # for p in range(len(adj_list)):
      max_depth = 0
      point = adj_list.pop(0)
      print(point)

      if 0<=point[0]<row and 0<=point[1]<col and visited[point[0]][point[1]] != -1:
        visited[point[0]][point[1]] = -1
        if maze[point[0]][point[1]] != '#':
          for adj in create_next_adj_list(point):
            adj_list.append(adj)
          if point[-1] > max_depth:
            max_depth = point[-1]

      result.append(max_depth)

print(max(result))

row,col=map(int,input().split())
maze=[list(input()) for _ in range(row)]
result = []
 
def create_next_adj_list(point):
  cur_x, cur_y, cur_depth = point
  return [(cur_x, cur_y+1, cur_depth+1), (cur_x+1, cur_y, cur_depth+1), (cur_x, cur_y-1, cur_depth+1), (cur_x-1, cur_y, cur_depth+1)]
 
for r in range(row):
  for c in range(col):
    if maze[r][c] == '.':
 
      visited = [ [0]*col for _ in range(row)]
      visited[r][c] = -1
    
      adj_list = [(r, c+1, 0), (r+1, c, 0), (r, c-1, 0), (r-1, c, 0)]

      while adj_list:
        point = adj_list.pop(0)

        if 0<=point[0]<row and 0<=point[1]<col and visited[point[0]][point[1]] != -1:
          visited[point[0]][point[1]] = -1
          if maze[point[0]][point[1]] != '#':
            for adj in create_next_adj_list(point):
              adj_list.append(adj)

      result.append(point[-1])

print(max(result))

Verdicts: Wrong Answer

Wrong Answer

Accepted