E - Charles in Chargehttps://vjudge.csgrandeur.cn/problem/Kattis-charlesincharge
#include <iostream>
#include <cstring>
#include <algorithm>
#include <queue>
using namespace std;
typedef long long ll;
#define int long long
#define endl '\n'
const int N = 1e6 + 10;
int read()
{
int x = 0, f = 1;
char c = getchar();
while (c < '0' || c > '9')
{
if (c == '-')
f = -1;
c = getchar();
}
while (c >= '0' && c <= '9')
x = x * 10 + c - '0', c = getchar();
return x * f;
}
signed int e[2 * N], ne[2 * N], h[N], w[2 * N], cnt;
bool st[N];
int dist[N];
const int INF = 0x3f3f3f3f;
typedef pair<int, int> PII;
int n, m, x;
void add(int a, int b, int c)
{
e[cnt] = b, w[cnt] = c, ne[cnt] = h[a], h[a] = cnt++;
}
bool dijkstra(int max, int lim)
{
memset(dist, 0x3f, sizeof dist);
memset(st, 0, sizeof st);
priority_queue<PII, vector<PII>, greater<PII>> q;
dist[1] = 0;
q.push({dist[1], 1});
while (q.size())
{
auto t = q.top().second;
q.pop();
if (st[t])
continue;
st[t] = true;
for (int i = h[t]; i != -1; i = ne[i])
{
int j = e[i];
if (dist[j] > dist[t] + w[i] && w[i] <= max)
{
dist[j] = dist[t] + w[i];
q.push({dist[j], j});
}
}
}
return (dist[n] <= lim);
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
n = read(), m = read(), x = read();
memset(h, -1, sizeof h);
while (m--)
{
int a, b, c;
a = read();
b = read();
c = read();
add(a, b, c);
add(b, a, c);
}
dijkstra(INF, INF);
int lim = dist[n] * (100 + x) / 100;
// cout << lim << endl;
int l = 0, r = lim ;
while (l < r)
{
int mid = l + r >> 1;
if (dijkstra(mid, lim))
r = mid;
else
l = mid + 1;
}
cout << l << endl;
return 0;
}