From 0ca3412af97879fdd4e69e715312d5d0a5910c89 Mon Sep 17 00:00:00 2001 From: LiiNi-coder <97495437+LiiNi-coder@users.noreply.github.com> Date: Mon, 24 Nov 2025 17:02:21 +0900 Subject: [PATCH] =?UTF-8?q?[20251124]=20BOJ=20/=20G4=20/=20=ED=8A=B8?= =?UTF-8?q?=EB=A6=AC=EC=9D=98=20=EA=B8=B0=EB=91=A5=EA=B3=BC=20=EA=B0=80?= =?UTF-8?q?=EC=A7=80=20/=20=EC=9D=B4=EC=9D=B8=ED=9D=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...5\352\263\274 \352\260\200\354\247\200.md" | 90 +++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 "LiiNi-coder/202511/24 BOJ \355\212\270\353\246\254\354\235\230 \352\270\260\353\221\245\352\263\274 \352\260\200\354\247\200.md" diff --git "a/LiiNi-coder/202511/24 BOJ \355\212\270\353\246\254\354\235\230 \352\270\260\353\221\245\352\263\274 \352\260\200\354\247\200.md" "b/LiiNi-coder/202511/24 BOJ \355\212\270\353\246\254\354\235\230 \352\270\260\353\221\245\352\263\274 \352\260\200\354\247\200.md" new file mode 100644 index 00000000..6e5bec5c --- /dev/null +++ "b/LiiNi-coder/202511/24 BOJ \355\212\270\353\246\254\354\235\230 \352\270\260\353\221\245\352\263\274 \352\260\200\354\247\200.md" @@ -0,0 +1,90 @@ +```java +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.*; +public class Main{ + static class Node{ + int nv; + int w; + Node(int nv, int w){ + this.nv = nv; this.w = w; + } + } + private static int N; + private static int R; + private static List> tree; + private static long maxLength = 0L; + private static boolean[] visited; + public static void main(String[] args) throws IOException { + String[] temp; + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + temp = br.readLine().split(" "); + N = Integer.parseInt(temp[0] ); + R = Integer.parseInt(temp[1]); + + visited = new boolean[N+1]; + tree = new ArrayList<>(); + for(int i = 0; i()); + } + + for(int i = 0; i nextNodes = tree.get(iterNode); + int size = 0; + Node nextNode = null; + for(Node node : nextNodes){ + if(visited[node.nv]){ + continue; + } + size++; + nextNode = node; + } + // 기둥 높이 카운트 + // if 기가노드 발견(자식이 2개이상) + if(size > 1 || size == 0){ + // - 기둥 높이 카운트 중지 & 탈출 + gigaNode = iterNode; + break; + } + height += nextNode.w; + iterNode = nextNode.nv; + } + + //System.out.println("height, giganode: "+ height + " " + gigaNode); + // 기가노드에서 부터 dfs시작 + dfs(gigaNode, 0); + System.out.println(height + " " + maxLength); + br.close(); + } + private static void dfs(int n, int length){ + visited[n] = true; + List nextNodes = tree.get(n); + if(nextNodes.size() == 1){ + // 리프 노드일때 + maxLength = Math.max(length, maxLength); + return; + } + for(Node nv : tree.get(n)){ + if(visited[nv.nv]){ + continue; + } + dfs(nv.nv, nv.w + length); + } + return; + } +} +```