-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathboj.11085.cc
74 lines (59 loc) · 1.47 KB
/
boj.11085.cc
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include <bits/stdc++.h>
#include <climits>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pull;
typedef const ll cll;
typedef queue<ll> qll;
typedef queue<pll> qpll;
typedef priority_queue<ll> pqll;
typedef priority_queue<pll> pqpll;
typedef vector<ll> vll;
typedef vector<pll> vpll;
typedef vector<vll> vvll;
typedef vector<vpll> vvpll;
cll P = 1000, W = 50000;
ll p, w, c, v, parents[P] = {};
vvpll mat(P);
ll findParent(ll node) {
if (node == parents[node]) {
return node;
}
return parents[node] = findParent(parents[node]);
}
inline void merge(ll n0, ll n1) { parents[n1] = findParent(n0); }
int main(void) {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> p >> w >> c >> v;
for (ll i = 0; i < p; ++i) {
parents[i] = i;
}
for (ll n0, n1, width, i = 0; i < w; ++i) {
cin >> n0 >> n1 >> width;
mat[n0].emplace_back(make_pair(n1, width));
mat[n1].emplace_back(make_pair(n0, width));
}
pqpll pq;
for (auto &p : mat[c]) {
pq.push(make_pair(p.second, p.first));
}
ll result = LLONG_MAX;
while (findParent(c) != findParent(v)) {
ll width = pq.top().first, node = pq.top().second;
pq.pop();
if (findParent(c) == findParent(node)) {
continue;
}
result = min(result, width);
merge(c, node);
for (auto &p : mat[node]) {
pq.push(make_pair(p.second, p.first));
}
}
cout << result << "\n";
return 0;
}