From 6104f479f84f618d810babac58f11b688d49d208 Mon Sep 17 00:00:00 2001 From: oncsr Date: Wed, 6 Aug 2025 18:52:04 +0900 Subject: [PATCH] =?UTF-8?q?[20250806]=20BOJ=20/=20P3=20/=20=EC=82=AC?= =?UTF-8?q?=ED=83=95=20=EB=B0=B0=EB=8B=AC=20/=20=EA=B6=8C=ED=98=81?= =?UTF-8?q?=EC=A4=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4\355\203\225 \353\260\260\353\213\254.md" | 160 ++++++++++++++++++ 1 file changed, 160 insertions(+) create mode 100644 "khj20006/202508/06 BOJ P3 \354\202\254\355\203\225 \353\260\260\353\213\254.md" diff --git "a/khj20006/202508/06 BOJ P3 \354\202\254\355\203\225 \353\260\260\353\213\254.md" "b/khj20006/202508/06 BOJ P3 \354\202\254\355\203\225 \353\260\260\353\213\254.md" new file mode 100644 index 00000000..8034b353 --- /dev/null +++ "b/khj20006/202508/06 BOJ P3 \354\202\254\355\203\225 \353\260\260\353\213\254.md" @@ -0,0 +1,160 @@ +```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[] c; + static List[] graph; + static int[] dep; + static int[][] par, bit; + static int[] king; + + public static void main(String[] args) throws Exception { + + io = new IOController(); + + init(); + solve(); + + io.close(); + + } + + static void init() throws Exception { + + N = io.nextInt(); + c = new int[N+1]; + graph = new List[N+1]; + king = new int[6]; + for(int i=1;i<=N;i++) { + graph[i] = new ArrayList<>(); + c[i] = io.nextInt(); + king[c[i]] = i; + } + + for(int i=1;i0) { + int cur = io.nextInt(); + int tar = io.nextInt(); + + int a = prev, b = cur; + prev = cur; + + int mask = 0; + int diff = Math.abs(dep[a] - dep[b]); + for(int k=0;k<17;k++) if((diff & (1< dep[b]) { + mask |= bit[a][k]; + a = par[a][k]; + } + else { + mask |= bit[b][k]; + b = par[b][k]; + } + } + + for(int k=16;k>=0;k--) if(par[a][k] != par[b][k]) { + mask |= bit[a][k] | bit[b][k]; + a = par[a][k]; + b = par[b][k]; + } + if(a != b) { + mask |= bit[a][0] | bit[b][0]; + a = par[a][0]; + b = par[b][0]; + } + mask |= (1<