Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[23주차] 배수빈 #316

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
jewan100 merged 6 commits into main from xubin
Feb 23, 2025
Merged
Changes from 1 commit
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
44 changes: 44 additions & 0 deletions BOJ/1000-5000번/SB_1135.java
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class SB_1135 {
static int N;
static List<List<Integer>> underling = new ArrayList<>();

private static int call(int node) {
ArrayList<Integer> lst = new ArrayList<>();

if (underling.get(node).isEmpty()) { // 리프노드면 0반환
return 0;
}

for (int ud : underling.get(node)) {
lst.add(call(ud)); // 각 부하들의 전화단계 구하기
}

lst.sort(Collections.reverseOrder());
for (int i = 0; i < lst.size(); i++) {
lst.set(i, lst.get(i) + i + 1);
}

return Collections.max(lst);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

헉 신기한 문법이네요.. 최댓값을 반환해주는건가

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

넵 리스트에서 Collections의 max를 통해 간단하게 최대값을 구할 수 있더라구요!

jewan100 reacted with thumbs up emoji
}
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
N = Integer.parseInt(br.readLine());
for (int i = 0; i < N; i++) {
underling.add(new ArrayList<>());
}

StringTokenizer st = new StringTokenizer(br.readLine());
for (int i = 0; i < N; i++) {
int boss = Integer.parseInt(st.nextToken());
if (boss==-1) continue;
underling.get(boss).add(i);
}

System.out.println(call(0));
}
}

AltStyle によって変換されたページ (->オリジナル) /