import networkx


def to_networkx(maze):
    """
    Return a NetworkX Graph representing maze.
    """
    # Undirected graph can represent a maze.
    G = networkx.Graph()
    # Add each node with positional information to retain the
    # visual memory of how the maze looks
    for r in range(maze.num_rows):
        for c in range(maze.num_cols):
            G.add_node((r, c), pos=(c, maze.num_rows - r))
    # An edge between two vertices exists IF THERE IS NO WALL
    for r in range(maze.num_rows):
        for c in range(maze.num_cols):
            if not maze.south_wall[r, c] and r < maze.num_rows - 1:
                G.add_edge((r, c), (r+1, c))
            if not maze.east_wall[r, c]:
                G.add_edge((r, c), (r, c+1))
    return G