华为OD机试真题 - 5G网络建设
并查集+Kruskal 算法 解决
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int num = Integer.parseInt(in.nextLine());
int n = Integer.parseInt(in.nextLine());
Map[] maps = new Map[n];
for (int i = 0; i < n; i++) {
int[] map = Arrays.stream(in.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
maps[i] = new Map(map[0], map[1], map[2], map[3] == 1);
}
Arrays.sort(maps, new Comparator
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int num = Integer.parseInt(in.nextLine());
int n = Integer.parseInt(in.nextLine());
Map[] maps = new Map[n];
for (int i = 0; i < n; i++) {
int[] map = Arrays.stream(in.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
maps[i] = new Map(map[0], map[1], map[2], map[3] == 1);
}
Arrays.sort(maps, new Comparator
全部评论
相关推荐