From da9b4baf3bebdee6920127d47bcee1991e192999 Mon Sep 17 00:00:00 2001 From: oncsr Date: Tue, 17 Jun 2025 22:15:22 +0900 Subject: [PATCH] =?UTF-8?q?[20250617]=20BOJ=20/=20P3=20/=20=EB=AC=BC?= =?UTF-8?q?=EB=A5=98=EC=B0=BD=EA=B3=A0=20/=20=EA=B6=8C=ED=98=81=EC=A4=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...74\353\245\230\354\260\275\352\263\240.md" | 127 ++++++++++++++++++ 1 file changed, 127 insertions(+) create mode 100644 "khj20006/202506/17 BOJ P3 \353\254\274\353\245\230\354\260\275\352\263\240.md" diff --git "a/khj20006/202506/17 BOJ P3 \353\254\274\353\245\230\354\260\275\352\263\240.md" "b/khj20006/202506/17 BOJ P3 \353\254\274\353\245\230\354\260\275\352\263\240.md" new file mode 100644 index 00000000..3cee5939 --- /dev/null +++ "b/khj20006/202506/17 BOJ P3 \353\254\274\353\245\230\354\260\275\352\263\240.md" @@ -0,0 +1,127 @@ +```java +import java.util.*; +import java.io.*; + +class IOController { + BufferedReader br; + BufferedWriter bw; + StringTokenizer st; + + public IOController() { + br = new BufferedReader(new InputStreamReader(System.in)); + bw = new BufferedWriter(new OutputStreamWriter(System.out)); + st = new StringTokenizer(""); + } + + String nextLine() throws Exception { + String line = br.readLine(); + st = new StringTokenizer(line); + return line; + } + + String nextToken() throws Exception { + while (!st.hasMoreTokens()) nextLine(); + return st.nextToken(); + } + + int nextInt() throws Exception { + return Integer.parseInt(nextToken()); + } + + long nextLong() throws Exception { + return Long.parseLong(nextToken()); + } + + double nextDouble() throws Exception { + return Double.parseDouble(nextToken()); + } + + void close() throws Exception { + bw.flush(); + bw.close(); + } + + void write(String content) throws Exception { + bw.write(content); + } + +} + +public class Main { + + static IOController io; + + // + + static int N, K, M; + static long[] ans; + static List Edges; + static TreeMap[] S; + static int[] r; + + static int f(int x) { return x==r[x] ? x : (r[x]=f(r[x])); } + + public static void main(String[] args) throws Exception { + + io = new IOController(); + + init(); + solve(); + + io.close(); + + } + + public static void init() throws Exception { + + N = io.nextInt(); + K = io.nextInt(); + M = io.nextInt(); + + r = new int[N+1]; + S = new TreeMap[N+1]; + for(int i=1;i<=N;i++) { + S[i] = new TreeMap<>(); + S[i].put(io.nextInt(), 1L); + r[i] = i; + } + + Edges = new ArrayList<>(); + for(int i=0;i b[2]-a[2]); + for(int[] e:Edges) { + int a = e[0], b = e[1], c = e[2]; + + int x = f(a), y = f(b); + if(x == y) continue; + int small = x, large = y; + if(S[x].size() > S[y].size()){ + small = y; + large = x; + } + + for(int key : S[small].keySet()) { + ans[key] += S[large].getOrDefault(key, 0L) * S[small].get(key) * c; + S[large].put(key, S[large].getOrDefault(key, 0L) + S[small].get(key)); + } + S[small] = new TreeMap<>(); + r[small] = large; + + } + + for(int i=1;i<=K;i++) io.write(ans[i] + "\n"); + + } + +} +```