#include <bits/stdc++.h>

#ifdef DEBUG
    #define debug(...) println(cerr, __VA_ARGS__)
#else
    #define debug(...)
#endif

#define forall(i,s,e) for(int i=(s);i<(e);i++)

using namespace std;

namespace rg = ranges;
namespace vw = views;

#define rev vw::reverse

using ll = long long;

using vb = vector<bool>;
using vi = vector<int>;
using vl = vector<ll>;

using aii = array<int, 2>;
using all = array<ll, 2>;

constexpr ll inf = 1e17;

void mincammino(int N, int M, vi X, vi Y, vi P, vl& D) {

    vector<vector<all>> G(N);

    forall(i, 0, M) {
        G[X[i]].push_back({Y[i], P[i]});
    }

    D.assign(N, inf);
    D[0] = 0;

    priority_queue<all> pq;

    pq.push({0, 0});

    while(!pq.empty()) {
        auto [d, v] = pq.top();
        pq.pop();
        d *= -1;

        if(d != D[v]) continue;

        for(auto [c, w]:G[v]) {
            if(D[c] > d + w) {
                D[c] = d + w;
                pq.push({-d-w, c});
            } 
        }
    }

    forall(i, 0, N) {
        if(D[i] == inf) D[i] = -1;
    }
}