From c2de58f005b6c4635c46d0fb86beac5c361b9804 Mon Sep 17 00:00:00 2001 From: lkhyun <102892446+lkhyun@users.noreply.github.com> Date: Tue, 10 Jun 2025 18:56:25 +0900 Subject: [PATCH] =?UTF-8?q?[20250610]=20BOJ=20/=20G3=20/=20ACM=20Craft=20/?= =?UTF-8?q?=20=EC=9D=B4=EA=B0=95=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lkhyun/202506/10 BOJ G3 ACM Craft.md | 71 ++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 lkhyun/202506/10 BOJ G3 ACM Craft.md diff --git a/lkhyun/202506/10 BOJ G3 ACM Craft.md b/lkhyun/202506/10 BOJ G3 ACM Craft.md new file mode 100644 index 00000000..f32fff40 --- /dev/null +++ b/lkhyun/202506/10 BOJ G3 ACM Craft.md @@ -0,0 +1,71 @@ +```java +import java.io.*; +import java.util.*; + +public class Main { + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + static StringTokenizer st; + static int N,K; + static int[] duration; + static List[] adjList; + static int[] degree; + static int[] minTime; + static int goal; + + public static void main(String[] args) throws IOException { + int T = Integer.parseInt(br.readLine()); + for (int t = 1; t <= T; t++) { + st = new StringTokenizer(br.readLine()); + N = Integer.parseInt(st.nextToken()); + K = Integer.parseInt(st.nextToken()); + duration = new int[N+1]; + adjList = new List[N+1]; + degree = new int[N+1]; + minTime = new int[N+1]; + + st = new StringTokenizer(br.readLine()); + for (int i = 1; i <= N; i++) { + duration[i] = Integer.parseInt(st.nextToken()); + minTime[i] = duration[i]; + } + for (int i = 1; i <= N; i++) { + adjList[i] = new ArrayList<>(); + } + for (int i = 0; i < K; i++) { + st = new StringTokenizer(br.readLine()); + int first = Integer.parseInt(st.nextToken()); + int second = Integer.parseInt(st.nextToken()); + adjList[first].add(second); + degree[second]++; + } + goal = Integer.parseInt(br.readLine()); + + go(); + } + + bw.close(); + } + public static void go() throws IOException { + ArrayDeque q = new ArrayDeque<>(); + for (int i = 1; i <= N; i++) { + if(degree[i] == 0){ + q.add(i); + } + } + + while(!q.isEmpty()) { + int cur = q.poll(); + for (int next : adjList[cur]) { + minTime[next] = Math.max(minTime[next], minTime[cur]+duration[next]); + + degree[next]--; + if(degree[next] == 0){ + q.add(next); + } + } + } + bw.write(minTime[goal]+"\n"); + } +} +```