diff --git "a/khj20006/202507/16 BOJ P5 \354\230\244\353\257\274\354\213\235\354\235\230 \352\263\240\353\257\274.md" "b/khj20006/202507/16 BOJ P5 \354\230\244\353\257\274\354\213\235\354\235\230 \352\263\240\353\257\274.md" new file mode 100644 index 00000000..cf8194b8 --- /dev/null +++ "b/khj20006/202507/16 BOJ P5 \354\230\244\353\257\274\354\213\235\354\235\230 \352\263\240\353\257\274.md" @@ -0,0 +1,149 @@ +```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 final long INF = -(long)1e18 + 7; + + static int N, M, A, B; + static int[] earn; + static List edges; + + public static void main(String[] args) throws Exception { + + io = new IOController(); + + init(); + solve(); + + io.close(); + + } + + public static void init() throws Exception { + + N = io.nextInt(); + A = io.nextInt(); + B = io.nextInt(); + M = io.nextInt(); + edges = new ArrayList<>(); + for(int i=0;i q = new ArrayDeque<>(); + boolean[] vis = new boolean[N]; + q.add(A); + vis[A] = true; + while(!q.isEmpty()){ + int cur = q.poll(); + fromA[cur] = true; + for(int[] edge: edges) if(edge[0] == cur) { + if(!vis[edge[1]]) { + q.add(edge[1]); + vis[edge[1]] = true; + } + } + } + + for(int i=0;i dist[from] + cost - earn[to])) { + dist[to] = dist[from] + cost - earn[to]; + if(step == N && fromA[to] && toB[to]) { + io.write("Gee"); + return; + } + } + } + } + + if(dist[B] == INF) io.write("gg"); + else io.write(-dist[B] + "\n"); + + } + +} +```