이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
///EVERYONE BELIEVE IN GODTAEGYU
#include<bits/stdc++.h>
using namespace std;
const long long INF = 1e15;
long long n, m, i, j, k;
long long x, h[100141];
long long dist[100141];
vector<pair<int,int>>graph[100141];
priority_queue<pair<long long, int>>pq;
int main(){
iostream::sync_with_stdio(0);cin.tie(0);cout.tie(0);
for(cin>>n>>m>>x; i++<n;)
{
cin>>h[i];
dist[i] = -INF;
}
for(;m--;)
{
cin>>i>>j>>k;
if(h[i] >= k)
graph[i].push_back({j, k});
if(h[j] >= k)
graph[j].push_back({i, k});
}
pq.push({x, 1});
while(!pq.empty())
{
tie(m, i) = pq.top();
pq.pop();
if(dist[i] != -INF)continue;
dist[i] = m;
for(auto next : graph[i])
{ //i = 현재 나무, m = 현재 높이, j = 다음 나무, k = 다음 나무 거리
tie(j, k) = next;
pq.push({min(m - k, h[j]), j});
}
}
if(dist[n] == -INF) cout<<-1;
else cout<<x + h[n] - dist[n] * 2;
/*
if 양수 -> 유지할 수 있는 최소 높이
따라서 (x-dist[n]) + (h[n]-dist[n])
if 음수 -> x는 다 쓴 이후 나무사이 가는데 최소거리(올라가는거 고려 X)
따라서 (h[n]-dist[n]) -> 올라가는데 필요한 비용
x-dist[n] -> 날아가는데 필요한 비용
*/
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |