diff --git a/kokeunho/.DS_Store b/kokeunho/.DS_Store index 090da24..714ee42 100644 Binary files a/kokeunho/.DS_Store and b/kokeunho/.DS_Store differ diff --git a/kokeunho/README.md b/kokeunho/README.md index 9c3b3ec..5c5f6cc 100644 --- a/kokeunho/README.md +++ b/kokeunho/README.md @@ -30,4 +30,5 @@ | 26차시 | 2025.05.19 | 분할 정복 | [별 찍기 - 10](https://www.acmicpc.net/problem/2447) | [#102](https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/102) | | 28차시 | 2025.07.01 | 구현 | [스도쿠](https://www.acmicpc.net/problem/2580) |[#116](https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/116) | | 29차시 | 2025.07.21 | 그래프 탐색 | [불!](https://www.acmicpc.net/problem/4179) |[#118](https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/118) | +| 30차시 | 2025.07.26 | 그래프 탐색 | [중량제한](https://www.acmicpc.net/problem/1939) |[#120](https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/120) | --- diff --git "a/kokeunho/\352\267\270\353\236\230\355\224\204 \355\203\220\354\203\211/30-kokeunho.java" "b/kokeunho/\352\267\270\353\236\230\355\224\204 \355\203\220\354\203\211/30-kokeunho.java" new file mode 100644 index 0000000..38b0641 --- /dev/null +++ "b/kokeunho/\352\267\270\353\236\230\355\224\204 \355\203\220\354\203\211/30-kokeunho.java" @@ -0,0 +1,79 @@ +import java.util.*; + +public class Main { + static int N, M; + static List> graph; + static class Node implements Comparable{ + int to; + int weight; + + public Node(int to, int weight) { + this.to = to; + this.weight = weight; + } + + @Override + public int compareTo(Node o) { + return this.weight - o.weight; + } + } + + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + + N = sc.nextInt(); + M = sc.nextInt(); + graph = new ArrayList<>(); + for (int i = 0; i <= N; i++) { + graph.add(new ArrayList<>()); + } + + int maxWeight = 0; + for (int i = 0; i < M; i++) { + int from = sc.nextInt(); + int to = sc.nextInt(); + int weight = sc.nextInt(); + graph.get(from).add(new Node(to, weight)); + graph.get(to).add(new Node(from, weight)); + maxWeight = Math.max(maxWeight, weight); + } + int A = sc.nextInt(); + int B = sc.nextInt(); + + int left = 1; + int right = maxWeight; + int answer = 0; + + while (left <= right) { + int mid = (left + right) / 2; + + if (bfs(A, B, mid)) { + answer = mid; + left = mid + 1; + } else { + right = mid - 1; + } + } + + System.out.print(answer); + } + static boolean bfs(int start, int end, int weightLimit) { + Queue queue = new LinkedList<>(); + boolean[] visited = new boolean[N + 1]; + queue.add(start); + visited[start] = true; + + while (!queue.isEmpty()) { + int now = queue.poll(); + if (now == end) return true; + + for (Node next : graph.get(now)) { + if (!visited[next.to] && next.weight >= weightLimit) { + queue.add(next.to); + visited[next.to] = true; + } + } + } + return false; + } +} \ No newline at end of file