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;
const int N = 1e5+5;
int n, m, x, h[N], mxh[N];
vector <pair <int, int>> adj[N];
int main() {
cin.tie(0)->sync_with_stdio(0);
cin >> n >> m >> x;
for(int i = 1; i <= n; ++i) cin >> h[i];
for(int i = 1; i <= m; ++i) {
int u, v, w; cin >> u >> v >> w;
if(h[u] >= w) adj[u].emplace_back(v, w);
if(h[v] >= w) adj[v].emplace_back(u, w);
}
fill(mxh+1, mxh+1+n, -1e9);
mxh[1] = x;
priority_queue <pair <int, int>> pq;
pq.push({x, 1});
while(pq.size()) {
pair <int, int> tp = pq.top(); pq.pop();
int hu = tp.first, u = tp.second;
if(hu < mxh[u]) continue;
for(pair <int, int> i : adj[u]) {
int v = i.first, w = i.second;
int hv = min(hu-w, h[v]);
if(hv > mxh[v]) {
mxh[v] = hv;
pq.push({hv, v});
}
}
}
if(mxh[n] == (int)-1e9) cout << "-1\n";
else cout << x + h[n] - 2*mxh[n] << '\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |