From 55b338152436ea95b6cd2ca779c758fe07032360 Mon Sep 17 00:00:00 2001 From: suyeun84 <81475092+suyeun84@users.noreply.github.com> Date: Wed, 29 Oct 2025 22:19:53 +0900 Subject: [PATCH] =?UTF-8?q?[20251029]=20BOJ/=20G4=20/=20=EC=9E=91=EC=97=85?= =?UTF-8?q?=20/=20=EA=B9=80=EC=88=98=EC=97=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../29 BOJ G4 \354\236\221\354\227\205.md" | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 "suyeun84/202510/29 BOJ G4 \354\236\221\354\227\205.md" diff --git "a/suyeun84/202510/29 BOJ G4 \354\236\221\354\227\205.md" "b/suyeun84/202510/29 BOJ G4 \354\236\221\354\227\205.md" new file mode 100644 index 00000000..e000d3c8 --- /dev/null +++ "b/suyeun84/202510/29 BOJ G4 \354\236\221\354\227\205.md" @@ -0,0 +1,50 @@ +```java +import java.io.*; +import java.util.*; + +public class boj2056 { + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + static StringTokenizer st; + static void nextLine() throws Exception {st = new StringTokenizer(br.readLine());} + static int nextInt() {return Integer.parseInt(st.nextToken());} + + public static void main(String[] args) throws Exception { + nextLine(); + int N = nextInt(); + int[] time = new int[N+1]; + int[] degree = new int[N + 1]; + int answer = 0; + ArrayList> work = new ArrayList<>(); + for (int i = 0; i < N+1; i++) work.add(new ArrayList<>()); + for (int i = 1; i <= N; i++) { + nextLine(); + time[i] = nextInt(); + int M = nextInt(); + for (int j = 0; j < M; j++) { + int num = nextInt(); + work.get(num).add(i); + degree[i]++; + } + } + // 위상 정렬 + Queue q = new LinkedList<>(); + int[] result = new int[N + 1]; + for (int i = 1; i <= N; i++) { + result[i] = time[i]; + if (degree[i] == 0) q.add(i); + } + + while(!q.isEmpty()) { + int cur = q.poll(); + for (int next : work.get(cur)) { + degree[next]--; + result[next] = Math.max(result[next], result[cur] + time[next]); + if (degree[next] == 0) q.add(next); + } + } + + for (int i = 0; i <= N; i++) answer = Math.max(answer, result[i]); + System.out.println(answer); + } +} +```