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); + } +} +```