From b264cae82d64947987534785b1f87a3ed1a7718e Mon Sep 17 00:00:00 2001 From: Jonghwan Lee <123362165+0224LJH@users.noreply.github.com> Date: Thu, 25 Sep 2025 21:47:51 +0900 Subject: [PATCH] =?UTF-8?q?[20250925]=20BOJ=20/=20G2=20/=20=EB=89=B4?= =?UTF-8?q?=EC=8A=A4=20=EC=A0=84=ED=95=98=EA=B8=B0=20/=20=EC=9D=B4?= =?UTF-8?q?=EC=A2=85=ED=99=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\244 \354\240\204\355\225\230\352\270\260" | 89 +++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 "0224LJH/202509/25 BOJ \353\211\264\354\212\244 \354\240\204\355\225\230\352\270\260" diff --git "a/0224LJH/202509/25 BOJ \353\211\264\354\212\244 \354\240\204\355\225\230\352\270\260" "b/0224LJH/202509/25 BOJ \353\211\264\354\212\244 \354\240\204\355\225\230\352\270\260" new file mode 100644 index 00000000..4d40bb55 --- /dev/null +++ "b/0224LJH/202509/25 BOJ \353\211\264\354\212\244 \354\240\204\355\225\230\352\270\260" @@ -0,0 +1,89 @@ +```java +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.*; + +public class Main { + + static int nodeCnt,ans; + static int[] parents; + static Node[] nodes; + + static class Node{ + int num; + int minute = 0; + HashSet children = new HashSet<>(); + + public Node (int num) { + this.num = num; + } + + public int calculate() { + + if (children.size() == 0) { + return 0; + } + PriorityQueue pq = new PriorityQueue<>(); + for (Node c: children) { + pq.add(c.calculate()); + } + + int min = 0; + while (!pq.isEmpty()) { + int num = pq.poll(); + min = Math.max(min, num+pq.size()+1); + } + + + + + return min; + } + + } + + + + + public static void main(String[] args) throws NumberFormatException, IOException { + init(); + process(); + print(); + } + + + + public static void init() throws NumberFormatException, IOException { + BufferedReader br= new BufferedReader(new InputStreamReader(System.in));; + nodeCnt = Integer.parseInt(br.readLine()); + parents = new int[nodeCnt]; + nodes = new Node[nodeCnt]; + ans = 0; + + StringTokenizer st = new StringTokenizer(br.readLine()); + for (int i = 0; i < nodeCnt; i++) { + nodes[i] = new Node(i); + parents[i] = Integer.parseInt(st.nextToken()); + + } + } + + + public static void process() throws IOException { + for (int i = 1; i< nodeCnt; i++) { + int parent = parents[i]; + nodes[parent].children.add(nodes[i]); + } + ans = nodes[0].calculate(); + + } + + + + + public static void print() { + System.out.println(ans); + } +} +```