比赛 2024暑假C班集训A 评测结果 AAAAAAAAAA
题目名称 行动!行动! 最终得分 100
用户昵称 darkMoon 运行时间 0.263 s
代码语言 C++ 内存使用 6.91 MiB
提交时间 2024-07-10 09:31:22
显示代码纯文本
#include<bits/stdc++.h>
#define int long long
#define fi first
#define se second
#define mp make_pair
using namespace std;
// #define fin cin
// #define fout cout
ifstream fin("move.in");
ofstream fout("move.out");
auto mread = [](){int x;fin >> x;return x;};
const int N = 10005;
int n = mread(), m = mread(), k = mread(), S = mread() + 1, T = mread() + 1, d[N][15], e[N][15];
vector<pair<int, int> > v[5 * N];
priority_queue<array<int, 3>, vector<array<int, 3> >, greater<array<int, 3> > > q;
signed main(){
    for(int i = 1, x, y, z; i <= m; i ++){
        x = mread() + 1, y = mread() + 1, z = mread();
        v[x].push_back(mp(y, z));
        v[y].push_back(mp(x, z));
    }
    memset(d, 0x3f, sizeof(d));
    d[S][0] = 0;
    q.push({0, S, 0});
    while(q.size()){
        auto x = q.top();
        q.pop();
        if(e[x[1]][x[2]]){
            continue;
        }
        e[x[1]][x[2]] = 1;
        // printf("*** %lld %lld %lld\n", x[1], x[2], x[0]);
        for(auto t : v[x[1]]){
            int y = t.fi, w = t.se;
            if(x[0] + w < d[y][x[2]]){
                d[y][x[2]] = x[0] + w;
                q.push({x[0] + w, y, x[2]});
            }
            if(x[2] < k){
                if(x[0] < d[y][x[2] + 1]){
                    d[y][x[2] + 1] = x[0];
                    q.push({x[0], y, x[2] + 1});
                }
            }
        }
    }
    int ans = LONG_LONG_MAX;
    for(int i = 0; i <= k; i ++)
    ans = min(ans, d[T][i]);
    fout << ans;
    return 0;
}