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;
#define ll long long
using pii = pair<int,int>;
const int MXN = 1e5+5;
vector<pii> E[MXN];
ll h[MXN], d[MXN];
int n,m,s;
void dijkstra(int x){
priority_queue<pii> pq; pq.push({0,x});
for(int i = 2;i<=n;i++) d[i] = 1LL<<62;
for(;pq.size();){
x = pq.top().second; pq.pop();
for(auto i : E[x]) if(h[x]>=i.second && d[i.first]>d[x]+i.second*2){
d[i.first] = d[x]+i.second*2;
pq.push({-d[i.first],i.first});
}
}
}
int main() {
cin.tie(0)->sync_with_stdio(0);
cin >> n >> m >> s;
for(int i = 1;i<=n;i++) cin >> h[i];
for(int i = 0;i<m;i++){
int a,b,c; cin >> a >> b >> c;
E[a].push_back({b,c});
E[b].push_back({a,c});
}
dijkstra(1);
if(d[n]==1LL<<62) cout << -1;
else cout << d[n]+h[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... |