From 9ef66292563dd3258b45a8eb7b80ca4cda97d98d Mon Sep 17 00:00:00 2001 From: lkhyun <102892446+lkhyun@users.noreply.github.com> Date: Mon, 12 Jan 2026 10:26:19 +0900 Subject: [PATCH] =?UTF-8?q?[20260112]=20BOJ=20/=20G3=20/=20=ED=8A=B8?= =?UTF-8?q?=EB=A6=AC=EB=A5=BC=20=EB=B3=B5=EC=9E=A1=ED=95=98=EA=B2=8C=20?= =?UTF-8?q?=EC=83=89=EC=B9=A0=ED=95=98=EB=8A=94=20=EC=B5=9C=EC=86=8C=20?= =?UTF-8?q?=EB=B9=84=EC=9A=A9=20/=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 --- ...4\354\206\214 \353\271\204\354\232\251.md" | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 "lkhyun/202601/12 BOJ G3 \355\212\270\353\246\254\353\245\274 \353\263\265\354\236\241\355\225\230\352\262\214 \354\203\211\354\271\240\355\225\230\353\212\224 \354\265\234\354\206\214 \353\271\204\354\232\251.md" diff --git "a/lkhyun/202601/12 BOJ G3 \355\212\270\353\246\254\353\245\274 \353\263\265\354\236\241\355\225\230\352\262\214 \354\203\211\354\271\240\355\225\230\353\212\224 \354\265\234\354\206\214 \353\271\204\354\232\251.md" "b/lkhyun/202601/12 BOJ G3 \355\212\270\353\246\254\353\245\274 \353\263\265\354\236\241\355\225\230\352\262\214 \354\203\211\354\271\240\355\225\230\353\212\224 \354\265\234\354\206\214 \353\271\204\354\232\251.md" new file mode 100644 index 00000000..7979dc91 --- /dev/null +++ "b/lkhyun/202601/12 BOJ G3 \355\212\270\353\246\254\353\245\274 \353\263\265\354\236\241\355\225\230\352\262\214 \354\203\211\354\271\240\355\225\230\353\212\224 \354\265\234\354\206\214 \353\271\204\354\232\251.md" @@ -0,0 +1,50 @@ +```java +import java.util.*; +import java.io.*; + +public class Main { + static int N; + static List[] adjList; + static long[][] dp; + static int[] whiteCost; + static int[] blackCost; + static StringTokenizer st; + + public static void main(String[] args) throws Exception { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + N = Integer.parseInt(br.readLine()); + adjList = new List[N]; + for (int i = 0; i < N; i++) { + adjList[i] = new ArrayList<>(); + } + dp = new long[N][2]; + whiteCost = new int[N]; + blackCost = new int[N]; + + for (int i = 1; i < N; i++) { + st = new StringTokenizer(br.readLine()); + int from = Integer.parseInt(st.nextToken()); + int to = Integer.parseInt(st.nextToken()); + adjList[from].add(to); + } + + for (int i = 0; i < N; i++) { + st = new StringTokenizer(br.readLine()); + whiteCost[i] = Integer.parseInt(st.nextToken()); + blackCost[i] = Integer.parseInt(st.nextToken()); + } + + dfs(0); + System.out.println(Math.min(dp[0][0],dp[0][1])); + } + public static void dfs(int cur){ + dp[cur][0] = whiteCost[cur]; + dp[cur][1] = blackCost[cur]; + for (Integer next : adjList[cur]) { + dfs(next); + dp[cur][0] += Math.min(dp[next][0],dp[next][1]); + dp[cur][1] += dp[next][0]; + } + } +} +```