def get_hop_distance(num_node, edge, max_hop=1):
    A = np.zeros((num_node, num_node))
    for (i, j) in edge:
        A[(j, i)] = 1
        A[(i, j)] = 1
    hop_dis = (np.zeros((num_node, num_node)) + np.inf)
    transfer_mat = [np.linalg.matrix_power(A, d) for d in range((max_hop + 1))]
    arrive_mat = (np.stack(transfer_mat) > 0)
    for d in range(max_hop, (- 1), (- 1)):
        hop_dis[arrive_mat[d]] = d
    return hop_dis
def get_hop_distance(num_node, edge, max_hop=1):
    A = np.zeros((num_node, num_node))
    for (i, j) in edge:
        A[(j, i)] = 1
        A[(i, j)] = 1
    hop_dis = (np.zeros((num_node, num_node)) + np.inf)
    transfer_mat = [np.linalg.matrix_power(A, d) for d in range((max_hop + 1))]
    arrive_mat = (np.stack(transfer_mat) > 0)
    for d in range(max_hop, (- 1), (- 1)):
        hop_dis[arrive_mat[d]] = d
    return hop_dis