From d017584adf6ded74412004c384e8c1b359d1ceb1 Mon Sep 17 00:00:00 2001 From: oncsr Date: Sun, 15 Jun 2025 23:54:15 +0900 Subject: [PATCH] =?UTF-8?q?[20250615]=20BOJ=20/=20D4=20/=20XOR=20MST=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 --- khj20006/202506/15 BOJ D4 XOR MST.md | 192 +++++++++++++++++++++++++++ 1 file changed, 192 insertions(+) create mode 100644 khj20006/202506/15 BOJ D4 XOR MST.md diff --git a/khj20006/202506/15 BOJ D4 XOR MST.md b/khj20006/202506/15 BOJ D4 XOR MST.md new file mode 100644 index 00000000..af75bf05 --- /dev/null +++ b/khj20006/202506/15 BOJ D4 XOR MST.md @@ -0,0 +1,192 @@ +```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); + } + +} + +class Node { + int count; + Node left, right; + Node(){ count = 0; } +} + +class Trie { + Node root; + Trie(){ root = new Node(); } + + void insert(int x) { + Node now = root; + int bit = 1<<29; + while(bit > 0) { + int val = x & bit; + if(val == 0) { + if(now.left == null) now.left = new Node(); + now = now.left; + } + else { + if(now.right == null) now.right = new Node(); + now = now.right; + } + now.count++; + bit >>= 1; + } + } + + void erase(int x) { + Node now = root; + eraseDfs(now, x, 1<<29); + } + + boolean eraseDfs(Node now, int x, int bit) { + if(bit == 0) return --now.count == 0; + int val = x & bit; + if(val == 0) { + if(eraseDfs(now.left, x, bit>>1)) now.left = null; + } + else { + if(eraseDfs(now.right, x, bit>>1)) now.right = null; + } + return --now.count == 0; + } + +} + +public class Main { + + static IOController io; + + // + + static int N; + static int[] A; + static Trie P, Q; + + public static void main(String[] args) throws Exception { + + io = new IOController(); + + init(); + solve(); + + io.close(); + + } + + public static void init() throws Exception { + + N = io.nextInt(); + A = new int[N]; + for(int i=0;i>1); + int[] res2 = find(p.right, q.right, bit>>1); + res2[1] |= bit; + if(res1[0] > res2[0]) return res2; + return res1; + } + if(c1) return find(p.left, q.left, bit>>1); + int[] res = find(p.right, q.right, bit>>1); + res[1] |= bit; + return res; + } + if(c3 && c4) { + int[] res1 = find(p.left, q.right, bit>>1); + res1[0] |= bit; + res1[1] |= bit; + int[] res2 = find(p.right, q.left, bit>>1); + res2[0] |= bit; + if(res1[0] > res2[0]) return res2; + return res1; + } + if(c3) { + int[] res = find(p.left, q.right, bit>>1); + res[0] |= bit; + res[1] |= bit; + return res; + } + int[] res = find(p.right, q.left, bit>>1); + res[0] |= bit; + return res; + + } + +} +```