CSES - Shared codeLink to this code: https://cses.fi/paste/14ab9da06facf43a307188/
#include <bits/stdc++.h>
#define REP(i,a,b) for (auto i = (a); i <= (b); ++i)
#define SIZE(x) int(size(x))
#define debug(x) cout << #x << " is " << x << el
#define el '\n'
using namespace std; using ll = long long;

const int N = 1e5+3;
int n, m, k;
vector<pair<ll,int>> adj[N];
priority_queue<pair<ll,int>> pq;
priority_queue<ll> dists[N];

int main() {
    cin.tie(0)->sync_with_stdio(0);
    cin >> n >> m >> k;
    REP(i,1,m) {
        int a, b, c; cin >> a >> b >> c;
        adj[a].push_back({b,c});
    }
    pq.push({0,1}); dists[1].push(0);
    while (not empty(pq)) {
        auto [d,a] = pq.top(); pq.pop(); d *= -1;
        if (d > dists[a].top()) continue;
        for (auto [b,w] : adj[a]) {
            if (SIZE(dists[b]) < k or dists[b].top() > d+w) {
                dists[b].push(d+w);
                pq.push({-d-w,b});
            }
            if (SIZE(dists[b]) > k) dists[b].pop();
        }
    }
    stack<ll> answer;
    REP(i,1,k) answer.push(dists[n].top()), dists[n].pop();
    while (not empty(answer)) cout << answer.top() << ' ', answer.pop();
}