-
Notifications
You must be signed in to change notification settings - Fork 0
/
중량제한.cpp
59 lines (51 loc) · 1.21 KB
/
중량제한.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <algorithm>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <vector>
using namespace std;
struct node {
int x, weight;
};
int n, m;
map<int, vector<node>> islands;
bool visit[20001];
bool bfs(int limit, int start, int end) {
queue<int> q;
q.push(start);
visit[start] = true;
while (!q.empty()) {
int x = q.front();
q.pop();
if (x == end)
return true;
for (auto elem : islands[x])
if (!visit[elem.x] && elem.weight >= limit) {
visit[elem.x] = true;
q.push(elem.x);
}
}
return false;
}
int main() {
int start, end, mini = 0, maxi = 1000000000;
cin >> n >> m;
while (m--) {
int a, b, c;
scanf("%d %d %d", &a, &b, &c);
islands[a].push_back({b, c});
islands[b].push_back({a, c});
}
cin >> start >> end;
int mid = 0;
while (mini <= maxi) {
mid = (mini + maxi) / 2;
memset(visit, false, sizeof(visit));
if (bfs(mid, start, end))
mini = mid + 1;
else
maxi = mid - 1;
}
cout << maxi;
}