From 745630ce64fb89d3ab44414067480aab6c121782 Mon Sep 17 00:00:00 2001 From: Jonghwan Lee <123362165+0224LJH@users.noreply.github.com> Date: Fri, 26 Sep 2025 19:28:14 +0900 Subject: [PATCH] =?UTF-8?q?[20250926]=20BOJ=20/=20G4=20/=20=EC=9E=91?= =?UTF-8?q?=EC=97=85=20/=20=EC=9D=B4=EC=A2=85=ED=99=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../26 BOJ \354\236\221\354\227\205.md" | 86 +++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 "0224LJH/202509/26 BOJ \354\236\221\354\227\205.md" diff --git "a/0224LJH/202509/26 BOJ \354\236\221\354\227\205.md" "b/0224LJH/202509/26 BOJ \354\236\221\354\227\205.md" new file mode 100644 index 00000000..a5508f21 --- /dev/null +++ "b/0224LJH/202509/26 BOJ \354\236\221\354\227\205.md" @@ -0,0 +1,86 @@ +```java +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.*; + +class Main { + + static int nodeCnt,ans; + static Node[] nodes; + + static class Node{ + int startTime = 0; + int cost; + int parentLeft; + + HashSet children = new HashSet<>(); + + public Node() { + + } + + } + + 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()); + nodes = new Node[nodeCnt+1]; + ans = 0; + + for (int i = 1; i <=nodeCnt; i++) { + nodes[i] = new Node(); + } + + for (int i = 1; i <= nodeCnt; i++) { + StringTokenizer st = new StringTokenizer(br.readLine()); + int cost = Integer.parseInt(st.nextToken()); + + nodes[i].cost = cost; + + int parentCnt = Integer.parseInt(st.nextToken()); + nodes[i].parentLeft = parentCnt; + for (int j = 0; j < parentCnt; j++) { + int nodeNum = Integer.parseInt(st.nextToken()); + nodes[nodeNum].children.add(nodes[i]); + } + + } + } + + public static void process() throws IOException { + Queue q = new LinkedList<>(); + + for (int i = 1; i<= nodeCnt; i++) { + if (nodes[i].parentLeft == 0) q.add(nodes[i]); + } + + + while(!q.isEmpty()) { + Node node = q.poll(); + + int newNum = node.cost + node.startTime; + ans = Math.max(newNum, ans); + + for (Node child: node.children) { + child.parentLeft--; + child.startTime = Math.max(child.startTime, newNum); + if (child.parentLeft == 0) q.add(child); + } + } + } + + + public static void print() { + System.out.println(ans); + } +} +```