From bba4869d658bf65b20e10de01cb5ede9e743cad0 Mon Sep 17 00:00:00 2001 From: oncsr Date: Sun, 27 Jul 2025 20:08:28 +0900 Subject: [PATCH] =?UTF-8?q?[20250727]=20BOJ=20/=20P5=20/=20=EB=82=B4=20?= =?UTF-8?q?=EC=99=BC=EC=86=90=EC=97=90=EB=8A=94=20=ED=9D=91=EC=97=BC?= =?UTF-8?q?=EB=A3=A1=EC=9D=B4=20=EC=9E=A0=EB=93=A4=EC=96=B4=20=EC=9E=88?= =?UTF-8?q?=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 --- ...4\354\226\264 \354\236\210\353\213\244.md" | 130 ++++++++++++++++++ 1 file changed, 130 insertions(+) create mode 100644 "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" 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); + } + } + +} +```