From 808e2cb28020565213a993b5c342b0efd9fbdf0b Mon Sep 17 00:00:00 2001 From: oncsr Date: Thu, 12 Mar 2026 06:55:03 +0900 Subject: [PATCH] =?UTF-8?q?[20260312]=20BOJ=20/=20D4=20/=20Internet=20Mono?= =?UTF-8?q?poly=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 --- .../202603/12 BOJ D4 Internet Monopoly.md | 127 ++++++++++++++++++ 1 file changed, 127 insertions(+) create mode 100644 khj20006/202603/12 BOJ D4 Internet Monopoly.md diff --git a/khj20006/202603/12 BOJ D4 Internet Monopoly.md b/khj20006/202603/12 BOJ D4 Internet Monopoly.md new file mode 100644 index 00000000..d88243dc --- /dev/null +++ b/khj20006/202603/12 BOJ D4 Internet Monopoly.md @@ -0,0 +1,127 @@ +```java +import java.io.*; +import java.util.*; + +public class BOJ29851 { + + static class Query { + int type, a, b; + Query(int a) { + this.type = 0; + this.a = a; + } + Query(int a, int b) { + this.type = 1; + this.a = a; + this.b = b; + } + } + + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + static StringTokenizer st; + + static int N, Q; + static Query[] queries; + static BitSet cantUnion; + static List[] tree; + static int[] root, parent, depth; + + public static int find(int x) { + return x == root[x] ? x : (root[x] = find(root[x])); + } + + public static boolean union(int a, int b) { + int x = find(a), y = find(b); + if(x == y) return false; + root[x] = y; + return true; + } + + public static void main(String[] args) throws Exception { + // 0. Input + Construct Tree + + st = new StringTokenizer(br.readLine()); + N = Integer.parseInt(st.nextToken()); + Q = Integer.parseInt(st.nextToken()); + + queries = new Query[Q]; + cantUnion = new BitSet(Q); + tree = new List[N+1]; + root = new int[N+1]; + for(int i=1;i<=N;i++) { + root[i] = i; + tree[i] = new ArrayList<>(); + } + for(int i=0;i depth[b]) { + union(a, parent[a]); + a = find(parent[a]); + } + else { + union(b, parent[b]); + b = find(parent[b]); + } + } + } + else { + if(nonBridges <= a && a <= N-1) { + bw.write("JAH\n"); + } + else { + bw.write("EI\n"); + } + } + } + bw.close(); + } + + public static void dfs(int cur, int par, int dep) { + parent[cur] = par; + depth[cur] = dep; + for(int nxt : tree[cur]) if(nxt != par) { + dfs(nxt, cur, dep+1); + } + } + +} +```