-
Notifications
You must be signed in to change notification settings - Fork 3
/
charlesincharge.cpp
71 lines (64 loc) · 1.28 KB
/
charlesincharge.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
60
61
62
63
64
65
66
67
68
69
70
71
#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using vi = vector<uint>;
using v2i = vector<vi>;
using ll = long long;
using vll = vector<ll>;
using ti2 = tuple<ll, uint>;
using vb = vector<bool>;
ll INF = 1e18;
struct edge;
using ve = vector<edge>;
using v2e = vector<ve>;
struct edge {
uint n, t;
edge() {}
edge(uint n, uint t) : n(n), t(t) {}
};
ll dijkstra(v2e &G, uint e_cap) {
priority_queue<ti2> Q;
vll D(G.size(), INF);
D[0] = 0;
Q.emplace(0, 0);
ll w;
uint n;
while (!Q.empty()) {
tie(w, n) = Q.top(), Q.pop();
for (auto &e : G[n]) {
if (e.t <= e_cap) {
ll nw = -w + e.t;
if (nw < D[e.n]) {
D[e.n] = nw;
Q.emplace(-nw, e.n);
}
}
}
}
return D.back();
}
int main() {
int n, m, x, a, b;
cin >> n >> m >> x;
v2e G(n);
vi T(m);
for (auto &t : T) {
cin >> a >> b >> t;
--a, --b;
G[a].push_back(edge(b, t));
G[b].push_back(edge(a, t));
}
ll d = dijkstra(G, 1e9);
d *= 100 + x;
d /= 100;
sort(T.begin(), T.end());
auto end = unique(T.begin(), T.end());
int lo = 0, hi = end - T.begin() - 1;
while (lo < hi) {
int mid = (lo + hi) / 2;
if (dijkstra(G, T[mid]) > d) lo = mid + 1;
else hi = mid;
}
cout << T[lo] << endl;
return 0;
}