别以为是什么高级算法,其实就是 $Floyd$算法不计算距离,只判断连通性...
public static void floyd(boolean[][] connect, int n) {
for (int k = 0; k < n; k++) {
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (!connect[i][j]) {
connect[i][j] = connect[i][k] && connect[k][j] ? true : false;
}
}
}
}
}