|
6 | 6 | // O(N) or O(N log N)
|
7 | 7 | // 두 마을을 분리, 마을 사이의 길의 유지비 합을 최소로
|
8 | 8 | // 크루스칼 알고리즘 : 가장 적은 비용으로 모든 노드를 연결하기 위해 사용하는 알고리즘 O(E log V)
|
9 | | -class Edge implements Comparable<Edge>{int cost; |
10 | | - int start; |
11 | | - int end; |
12 | 9 |
|
13 | 10 |
|
14 | | - Edge(int start, int end, int cost){ |
15 | | - this.start = start; |
16 | | - this.end = end; |
17 | | - this.cost = cost; |
18 | | - } |
| 11 | +public class HW_1647 { |
| 12 | + static class Edge implements Comparable<Edge>{int cost; |
| 13 | + int start; |
| 14 | + int end; |
19 | 15 |
|
20 | | - @Override |
21 | | - public int compareTo(Edge o){ |
22 | | - return this.cost - o.cost; |
23 | | - } |
24 | | -} |
25 | 16 |
|
26 | | -public class HW_1647 { |
| 17 | + Edge(int start, int end, int cost){ |
| 18 | + this.start = start; |
| 19 | + this.end = end; |
| 20 | + this.cost = cost; |
| 21 | + } |
| 22 | + |
| 23 | + @Override |
| 24 | + public int compareTo(Edge o){ |
| 25 | + return this.cost - o.cost; |
| 26 | + } |
| 27 | + } |
27 | 28 | static int N, M;
|
28 | 29 | static List<Edge> arr = new ArrayList<>();
|
29 | 30 | static int[] parent;
|
|
0 commit comments