diff --git "a/khj20006/202507/27 BOJ P5 \353\202\264 \354\231\274\354\206\220\354\227\220\353\212\224 \355\235\221\354\227\274\353\243\241\354\235\264 \354\236\240\353\223\244\354\226\264 \354\236\210\353\213\244.md" "b/khj20006/202507/27 BOJ P5 \353\202\264 \354\231\274\354\206\220\354\227\220\353\212\224 \355\235\221\354\227\274\353\243\241\354\235\264 \354\236\240\353\223\244\354\226\264 \354\236\210\353\213\244.md" new file mode 100644 index 00000000..71493505 --- /dev/null +++ "b/khj20006/202507/27 BOJ P5 \353\202\264 \354\231\274\354\206\220\354\227\220\353\212\224 \355\235\221\354\227\274\353\243\241\354\235\264 \354\236\240\353\223\244\354\226\264 \354\236\210\353\213\244.md" @@ -0,0 +1,130 @@ +```java +import java.util.*; +import java.io.*; + +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 List[] graph; + static int[] down, up; + + public static void main(String[] args) throws Exception { + + io = new IOController(); + + init(); + solve(); + + io.close(); + + } + + static void init() throws Exception { + + N = io.nextInt(); + graph = new ArrayList[N+1]; + for(int i=1;i<=N;i++) graph[i] = new ArrayList<>(); + down = new int[N+1]; + up = new int[N+1]; + for(int i=1;i max1) { + max2 = max1; + max1 = down[e[0]] + e[1]; + num1 = e[0]; + } + else if(down[e[0]] + e[1] > max2) { + max2 = down[e[0]] + e[1]; + } + } + for(int[] e:graph[n]) if(e[0] != p) { + if(e[0] == num1) { + up[e[0]] = Math.max(up[n], max2) + e[1]; + } + else { + up[e[0]] = Math.max(up[n], max1) + e[1]; + } + dfs2(e[0], n); + } + } + +} +```