This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define x first
#define y second
ll N, M, X;
ll H[100005];
vector<pair<ll, ll>> G[100005];
const ll INF = 1e15;
ll mh[100005];
int main(){
cin.tie(0) -> sync_with_stdio(false);
cin >> N >> M >> X;
for(int i = 1; i <= N; i++){
cin >> H[i];
mh[i] = INF;
}
for(int i = 1; i <= M; i++){
ll u, v, c; cin >> u >> v >> c;
if(H[u] >= c) G[u].push_back({v, c});
if(H[v] >= c) G[v].push_back({u, c});
}
priority_queue<pair<ll, ll>> PQ;
PQ.push({X, 1});
while(!PQ.empty()){
ll d = PQ.top().x, u = PQ.top().y; PQ.pop();
if(mh[u] != INF) continue;
mh[u] = d;
for(auto i : G[u]){
if(mh[i.x] != INF) continue;
PQ.push({min(d - i.y, H[i.x]), i.x});
}
}
cout << (mh[N] == INF ? -1 : X + H[N] - mh[N] * 2);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |