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<