E - Charles in Charge

E - Charles in Chargeicon-default.png?t=M666https://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;
}

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值