input: from typing import List
  
  def solve_maze(grid: List[List[int]]) -> List[int]:
      """ Solve a given maze represented as a 2D list of integers where 1 represents a path and 0 represents a wall.
      The maze starts at the top-left corner (0, 0) and ends at the bottom-right corner (n-1, m-1).
      The function returns the shortest path distances as a list of integers.
      If no path is found, it returns an empty list.
  
      >>> solve_maze([[1, 0, 1], [1, 1, 1], [0, 0, 1]])
      [2]
      >>> solve_maze([[1, 0, 0], [1, 1, 1], [0, 0, 1]])
      []
      """
      n, m = len(grid), len(grid[0])
      maze = Maze(n, m)
      maze._grid = grid
      return maze.solve_maze()
output:     from collections import deque
  
      class Maze:
          def __init__(self, n, m):
              self.n = n
              self.m = m
              self.grid = [[0] * m for _ in range(n)]
              self.dist = [[float('inf')] * m for _ in range(n)]
          
          def solve_maze(self):
              if self.grid[0][0] == 0 or self.grid[self.n-1][self.m-1] == 0:
                  return []
              
              queue = deque([(0, 0)])
              self.dist[0][0] = 0
              
              directions = [(-1, 0), (1, 0), (0, -1), (0, 1)]
              
              while queue:
                  x, y = queue.popleft()
                  
                  for dx, dy in directions:
                      nx, ny = x + dx, y + dy
                      
                      if 0 <= nx < self.n and 0 <= ny < self.m and self.grid[nx][ny] == 1:
                          if self.dist[nx][ny] == float('inf'):
                              self.dist[nx][ny] = self.dist[x][y] + 1
                              queue.append((nx, ny))
              
              if self.dist[self.n-1][self.m-1] == float('inf'):
                  return []
              else:
                  return [self.dist[self.n-1][self.m-1]]