diff --git "a/1197_\354\265\234\354\206\214 \354\212\244\355\214\250\353\213\235 \355\212\270\353\246\254.java" "b/1197_\354\265\234\354\206\214 \354\212\244\355\214\250\353\213\235 \355\212\270\353\246\254.java" new file mode 100644 index 0000000..0e35b3a --- /dev/null +++ "b/1197_\354\265\234\354\206\214 \354\212\244\355\214\250\353\213\235 \355\212\270\353\246\254.java" @@ -0,0 +1,81 @@ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.PriorityQueue; +import java.util.StringTokenizer; + +public class Main { + + static class Edge implements Comparable{ + int from, to; + int weight; + + public Edge(int from, int to, int weight) { + super(); + this.from = from; + this.to = to; + this.weight = weight; + } + @Override + public int compareTo(Edge o) { + return Integer.compare(this.weight, o.weight); + } + } + + static int V, E; + static int[] parents; + + static void make() { //초기화 메서드 + parents = new int[V]; + for (int i = 0; i < V; i++) { + parents[i] = i; + } + } + + static int find(int a) { //root노드 찾아주는 메서드 + if(parents[a] == a) return a; + return parents[a] = find(parents[a]); + } + + static boolean union(int a, int b) { //b의 root 변경 메서드 + int aRoot = find(a); + int bRoot = find(b); + if(aRoot == bRoot) return false; + parents[bRoot] = aRoot; + return true; + } + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()," "); + + V = Integer.parseInt(st.nextToken()) + 1; //정점 1부터 시작 + E = Integer.parseInt(st.nextToken()); + + PriorityQueue pq = new PriorityQueue<>(); //우선순위 큐 사용 + + for(int i=0; i