def secondMinEdge(graph, i, vertices):
    """
    Returns the second minimum edge weight in the graph, ending at vertex i.
    """

    min, secondMin = float('inf'), float('inf')
    for j in range(vertices):
        if(i == j):
            continue

        x = graph[i][j]
        if(x <= min):
            secondMin = min
            min = x

        elif(x <= secondMin and x != min):
            secondMin = x

    return secondMin