# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
153918 | mhy908 | 날다람쥐 (JOI14_ho_t4) | C++14 | 514 ms | 47468 KiB |
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>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define llinf 8987654321987654321
#define inf 1987654321
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
int n, m;
LL x;
LL h[100010];
vector<pair<int, LL> > link[100010];
priority_queue<pair<LL, pair<int, LL> > > pq;
LL dijk[100010];
int main()
{
scanf("%d %d %d", &n, &m, &x);
for(int i=1; i<=n; i++)scanf("%lld", &h[i]);
for(int i=1; i<=m; i++){
int a, b;
LL c;
scanf("%d %d %lld", &a, &b, &c);
link[a].pb({b, c});
link[b].pb({a, c});
}
pq.push({0, {-1, -x}});
for(int i=1; i<=n; i++)dijk[i]=llinf;
while(!pq.empty()){
int here=-pq.top().S.F;
LL x=-pq.top().S.S;
LL c=-pq.top().F;
pq.pop();
if(c>=dijk[here])continue;
dijk[here]=c;
for(int i=0; i<link[here].size(); i++){
int next=link[here][i].F;
if(h[here]<link[here][i].S)continue;
if(x-link[here][i].S>h[link[here][i].F]){
//printf("%lld %d %lld\n", c+x-h[link[here][i].F]+link[here][i].S, link[here][i].F, h[link[here][i].F]);
pq.push({-(c+x-(h[link[here][i].F]+link[here][i].S)+link[here][i].S), {-link[here][i].F, -h[link[here][i].F]}});
}
else if(x>=link[here][i].S){
//printf("%lld %d %lld\n", c+link[here][i].S, link[here][i].F, x-link[here][i].S);
pq.push({-(c+link[here][i].S), {-link[here][i].F, -(x-link[here][i].S)}});
}
else{
//printf("%lld %d %lld\n", c+link[here][i].S*2-x, link[here][i].F, 0ll);
pq.push({-(c+link[here][i].S*2-x), {-link[here][i].F, 0ll}});
}
}
}
if(dijk[n]==llinf)printf("-1");
else printf("%lld", dijk[n]+h[n]);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |