이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |