From 0fe8639e488ee1e9f617de331219d46cae45badd Mon Sep 17 00:00:00 2001 From: oncsr Date: Sat, 27 Sep 2025 23:53:58 +0900 Subject: [PATCH] =?UTF-8?q?[20250927]=20BOJ=20/=20P2=20/=20=EC=9D=B8?= =?UTF-8?q?=EC=83=9D=EC=9D=80=20B=EC=99=80=20D=20=EC=82=AC=EC=9D=B4?= =?UTF-8?q?=EC=9D=98=20C=EB=8B=A4=20/=20=EA=B6=8C=ED=98=81=EC=A4=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\354\235\264\354\235\230 C\353\213\244.md" | 124 ++++++++++++++++++ 1 file changed, 124 insertions(+) create mode 100644 "khj20006/202509/27 BOJ P2 \354\235\270\354\203\235\354\235\200 B\354\231\200 D \354\202\254\354\235\264\354\235\230 C\353\213\244.md" diff --git "a/khj20006/202509/27 BOJ P2 \354\235\270\354\203\235\354\235\200 B\354\231\200 D \354\202\254\354\235\264\354\235\230 C\353\213\244.md" "b/khj20006/202509/27 BOJ P2 \354\235\270\354\203\235\354\235\200 B\354\231\200 D \354\202\254\354\235\264\354\235\230 C\353\213\244.md" new file mode 100644 index 00000000..30611b85 --- /dev/null +++ "b/khj20006/202509/27 BOJ P2 \354\235\270\354\203\235\354\235\200 B\354\231\200 D \354\202\254\354\235\264\354\235\230 C\353\213\244.md" @@ -0,0 +1,124 @@ +```java +import java.io.*; +import java.util.*; + +class IOController { + BufferedReader br; + BufferedWriter bw; + StringTokenizer st; + + public IOController() { + br = new BufferedReader(new InputStreamReader(System.in)); + bw = new BufferedWriter(new OutputStreamWriter(System.out)); + st = new StringTokenizer(""); + } + + String nextLine() throws Exception { + String line = br.readLine(); + st = new StringTokenizer(line); + return line; + } + + String nextToken() throws Exception { + while (!st.hasMoreTokens()) + nextLine(); + return st.nextToken(); + } + + int nextInt() throws Exception { + return Integer.parseInt(nextToken()); + } + + long nextLong() throws Exception { + return Long.parseLong(nextToken()); + } + + double nextDouble() throws Exception { + return Double.parseDouble(nextToken()); + } + + void close() throws Exception { + bw.flush(); + bw.close(); + } + + void write(String content) throws Exception { + bw.write(content); + } + +} + +public class Main { + + static IOController io; + + // + + static int N; + static long B, D; + static List[] tree; + static long[] s; + static long[][] dp; + + public static void main(String[] args) throws Exception { + + io = new IOController(); + + N = io.nextInt(); + B = io.nextInt(); + D = io.nextInt(); + tree = new List[N+1]; + s = new long[N+1]; + dp = new long[N+1][35]; + for(int i=1;i<=N;i++) tree[i] = new ArrayList<>(); + + for(int i=1;i tmp = new ArrayList<>(); + for(int i:tree[n]) if(i != p) { + tmp.add(new long[]{D*s[i] - dp[i][h-1], i}); + } + Collections.sort(tmp, (a,b) -> Long.compare(b[0],a[0])); + if(children == 1) { + dp[n][h] = dp[(int)tmp.get(0)[1]][h-1] + B*((1L<