diff --git a/boj/solved/disjoint_set/16562/Main.java b/boj/solved/disjoint_set/16562/Main.java new file mode 100644 index 0000000..f19f926 --- /dev/null +++ b/boj/solved/disjoint_set/16562/Main.java @@ -0,0 +1,66 @@ +import java.io.*; +import java.util.*; + +class Main { + static int n, m, k; + static int[] w; + static int[] friends; + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + + n = Integer.parseInt(st.nextToken()); + m = Integer.parseInt(st.nextToken()); + k = Integer.parseInt(st.nextToken()); + friends = new int[n+1]; + w = new int[n+1]; + st = new StringTokenizer(br.readLine()); + for(int i = 1;i<=n;i++) { + friends[i] = i; + w[i] = Integer.parseInt(st.nextToken()); + } + + for(int i = 0;i k) { + System.out.println("Oh no"); + } + else { + System.out.println(res); + } + } + + public static int find(int id) { + if (friends[id] == id) { + return id; + } + return friends[id] = find(friends[id]); + } + + public static void union(int a, int b) { + int friendA = find(a); + int friendB = find(b); + if (friendA == friendB) { + return; + } + + if (w[friendA] > w[friendB]) { + friends[friendA] = friendB; + } + else { + friends[friendB] = friendA; + } + } +} \ No newline at end of file