diff --git "a/khj20006/202502/11 BOJ P5 \353\254\274\354\225\275.md" "b/khj20006/202502/11 BOJ P5 \353\254\274\354\225\275.md" new file mode 100644 index 00000000..a98be617 --- /dev/null +++ "b/khj20006/202502/11 BOJ P5 \353\254\274\354\225\275.md" @@ -0,0 +1,122 @@ +```java + +import java.util.*; +import java.io.*; + +class Node { + int cnt; + String ingredient; + Node(int cnt, String ingredient){ + this.cnt = cnt; + this.ingredient = ingredient; + } +} + +class Main { + + // IO field + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + static StringTokenizer st; + + static void nextLine() throws Exception {st = new StringTokenizer(br.readLine());} + static int nextInt() {return Integer.parseInt(st.nextToken());} + static long nextLong() {return Long.parseLong(st.nextToken());} + static void bwEnd() throws Exception {bw.flush();bw.close();} + + // Additional field + static final int INF = 1000000001; + + static int N, M; + static HashMap price = new HashMap<>(); + static String[] newIngredients; + static List[] expressions; + static boolean[] clear; + + public static void main(String[] args) throws Exception { + + ready(); + solve(); + + bwEnd(); + } + + static void ready() throws Exception{ + + nextLine(); + N = nextInt(); + M = nextInt(); + for(int i=0;i(); + for(int j=0;j= INF) break; + int value = price.get(node.ingredient); + for(int k=0;k= INF) { + res = INF; + break; + } + res += value; + } + } + if(price.containsKey(newIngredients[i])) { + if(res < price.get(newIngredients[i])) { + price.put(newIngredients[i], res); + change = true; + + } + } + else { + price.put(newIngredients[i], res); + change = true; + } + + + } + + }while(change); + + if(price.containsKey("LOVE")) bw.write(price.get("LOVE")+"\n"); + else bw.write("-1"); + + } + + +} + +```