From 1a911a55f5b2a68faa9f2e5c8d39877729f949f3 Mon Sep 17 00:00:00 2001 From: oncsr Date: Sat, 19 Jul 2025 18:46:45 +0900 Subject: [PATCH] =?UTF-8?q?[20250719]=20BOJ=20/=20D4=20/=20=EC=8A=B9?= =?UTF-8?q?=ED=98=84=EC=9D=B4=EC=99=80=20=EC=8A=B9=ED=98=84=EC=9D=B4=20/?= =?UTF-8?q?=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 --- ...0 \354\212\271\355\230\204\354\235\264.md" | 184 ++++++++++++++++++ 1 file changed, 184 insertions(+) create mode 100644 "khj20006/202507/19 BOJ D4 \354\212\271\355\230\204\354\235\264\354\231\200 \354\212\271\355\230\204\354\235\264.md" diff --git "a/khj20006/202507/19 BOJ D4 \354\212\271\355\230\204\354\235\264\354\231\200 \354\212\271\355\230\204\354\235\264.md" "b/khj20006/202507/19 BOJ D4 \354\212\271\355\230\204\354\235\264\354\231\200 \354\212\271\355\230\204\354\235\264.md" new file mode 100644 index 00000000..a9d28914 --- /dev/null +++ "b/khj20006/202507/19 BOJ D4 \354\212\271\355\230\204\354\235\264\354\231\200 \354\212\271\355\230\204\354\235\264.md" @@ -0,0 +1,184 @@ +```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, M; + static int[] cost; + static List[] graph; + static List edges; + static int[] r, depth; + static int[][] parent, min; + + public 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(); + M = io.nextInt(); + cost = new int[N]; + for(int i=0;i(); + r[i] = i; + int x = i/N, y = i%N; + } + edges = new ArrayList<>(); + while(M-->0) { + int u = io.nextInt() - 1; + int v = io.nextInt() - 1; + for(int i=0;i0) { + int u = io.nextInt() - 1; + int v = io.nextInt() - 1; + int from = u*N + v; + int to = v*N + u; + + io.write(getMinValue(from, to) + "\n"); + } + + } + + static void constructMST() { + Collections.sort(edges, (a,b) -> a[2]-b[2]); + for(int[] edge : edges) { + int a = edge[0], b = edge[1], c = edge[2]; + int x = f(a), y = f(b); + if(x == y) continue; + r[x] = y; + graph[a].add(new int[]{b,c}); + graph[b].add(new int[]{a,c}); + } + } + + static void dfs(int n, int p, int d) { + depth[n] = d; + parent[n][0] = p; + for(int[] e:graph[n]) if(e[0] != p) { + dfs(e[0], n, d+1); + min[e[0]][0] = e[1]; + } + } + + static void constructSparseTable() { + for(int k=1;k<18;k++) for(int i=0;i depth[b]) { + result = Math.max(result, min[a][k]); + a = parent[a][k]; + } + else { + result = Math.max(result, min[b][k]); + b = parent[b][k]; + } + } + + for(int k=17;k>=0;k--) if(parent[a][k] != parent[b][k]) { + result = Math.max(result, Math.max(min[a][k], min[b][k])); + a = parent[a][k]; + b = parent[b][k]; + } + if(a != b) { + result = Math.max(result, Math.max(min[a][0], min[b][0])); + } + + return result; + + } + +} +```