Submission #1090711

#TimeUsernameProblemLanguageResultExecution timeMemory
1090711trandangquang날다람쥐 (JOI14_ho_t4)C++14
100 / 100
97 ms17032 KiB
#include <bits/stdc++.h> using namespace std; const int N = 1e5+5; using ll = long long; int n, m, x, h[N]; ll 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, -1e18); mxh[1] = x; priority_queue <pair <ll, int>> pq; pq.push({x, 1}); while(pq.size()) { pair <ll, int> tp = pq.top(); pq.pop(); ll hu = tp.first; int u = tp.second; if(hu < mxh[u]) continue; for(pair <int, int> i : adj[u]) { int v = i.first, w = i.second; ll hv = min(hu-w, (ll)h[v]); if(hv > mxh[v]) { mxh[v] = hv; pq.push({hv, v}); } } } if(mxh[n] == (ll)-1e18) cout << "-1\n"; else cout << x + h[n] - 2*mxh[n] << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...