| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 153918 | mhy908 | 날다람쥐 (JOI14_ho_t4) | C++14 | 514 ms | 47468 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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]);
}
컴파일 시 표준 에러 (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... | ||||
