Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified kokeunho/.DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions kokeunho/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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) |
---
79 changes: 79 additions & 0 deletions kokeunho/๊ทธ๋ž˜ํ”„ ํƒ์ƒ‰/30-kokeunho.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import java.util.*;

public class Main {
static int N, M;
static List<List<Node>> graph;
static class Node implements Comparable<Node>{
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<Integer> 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;
}
}