Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 89 additions & 0 deletions 0224LJH/202509/25 BOJ 뉴스 전하기
Original file line number Diff line number Diff line change
@@ -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<Node> children = new HashSet<>();

public Node (int num) {
this.num = num;
}

public int calculate() {

if (children.size() == 0) {
return 0;
}
PriorityQueue<Integer> 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);
}
}
```