# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
153918 | 2019-09-17T13:31:37 Z | mhy908 | 날다람쥐 (JOI14_ho_t4) | C++14 | 514 ms | 47468 KB |
#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
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 2680 KB | Output is correct |
2 | Correct | 8 ms | 2936 KB | Output is correct |
3 | Correct | 6 ms | 2936 KB | Output is correct |
4 | Correct | 5 ms | 2808 KB | Output is correct |
5 | Correct | 18 ms | 2812 KB | Output is correct |
6 | Correct | 5 ms | 2680 KB | Output is correct |
7 | Correct | 6 ms | 2808 KB | Output is correct |
8 | Correct | 7 ms | 2936 KB | Output is correct |
9 | Correct | 12 ms | 2936 KB | Output is correct |
10 | Correct | 7 ms | 2936 KB | Output is correct |
11 | Correct | 5 ms | 2680 KB | Output is correct |
12 | Correct | 7 ms | 2936 KB | Output is correct |
13 | Correct | 7 ms | 2936 KB | Output is correct |
14 | Correct | 5 ms | 2808 KB | Output is correct |
15 | Correct | 6 ms | 2936 KB | Output is correct |
16 | Correct | 6 ms | 2728 KB | Output is correct |
17 | Correct | 5 ms | 2680 KB | Output is correct |
18 | Correct | 5 ms | 2680 KB | Output is correct |
19 | Correct | 5 ms | 2808 KB | Output is correct |
20 | Correct | 5 ms | 2808 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 362 ms | 24344 KB | Output is correct |
2 | Correct | 476 ms | 35956 KB | Output is correct |
3 | Correct | 212 ms | 15216 KB | Output is correct |
4 | Correct | 463 ms | 35032 KB | Output is correct |
5 | Correct | 514 ms | 47468 KB | Output is correct |
6 | Correct | 14 ms | 3832 KB | Output is correct |
7 | Correct | 325 ms | 23672 KB | Output is correct |
8 | Correct | 383 ms | 26720 KB | Output is correct |
9 | Correct | 280 ms | 22904 KB | Output is correct |
10 | Correct | 200 ms | 18808 KB | Output is correct |
11 | Correct | 33 ms | 5052 KB | Output is correct |
12 | Correct | 235 ms | 23196 KB | Output is correct |
13 | Correct | 174 ms | 25316 KB | Output is correct |
14 | Correct | 306 ms | 23464 KB | Output is correct |
15 | Correct | 11 ms | 3368 KB | Output is correct |
16 | Correct | 434 ms | 35768 KB | Output is correct |
17 | Correct | 28 ms | 4728 KB | Output is correct |
18 | Correct | 31 ms | 5108 KB | Output is correct |
19 | Correct | 107 ms | 12024 KB | Output is correct |
20 | Correct | 39 ms | 5368 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 2680 KB | Output is correct |
2 | Correct | 8 ms | 2936 KB | Output is correct |
3 | Correct | 6 ms | 2936 KB | Output is correct |
4 | Correct | 5 ms | 2808 KB | Output is correct |
5 | Correct | 18 ms | 2812 KB | Output is correct |
6 | Correct | 5 ms | 2680 KB | Output is correct |
7 | Correct | 6 ms | 2808 KB | Output is correct |
8 | Correct | 7 ms | 2936 KB | Output is correct |
9 | Correct | 12 ms | 2936 KB | Output is correct |
10 | Correct | 7 ms | 2936 KB | Output is correct |
11 | Correct | 5 ms | 2680 KB | Output is correct |
12 | Correct | 7 ms | 2936 KB | Output is correct |
13 | Correct | 7 ms | 2936 KB | Output is correct |
14 | Correct | 5 ms | 2808 KB | Output is correct |
15 | Correct | 6 ms | 2936 KB | Output is correct |
16 | Correct | 6 ms | 2728 KB | Output is correct |
17 | Correct | 5 ms | 2680 KB | Output is correct |
18 | Correct | 5 ms | 2680 KB | Output is correct |
19 | Correct | 5 ms | 2808 KB | Output is correct |
20 | Correct | 5 ms | 2808 KB | Output is correct |
21 | Correct | 362 ms | 24344 KB | Output is correct |
22 | Correct | 476 ms | 35956 KB | Output is correct |
23 | Correct | 212 ms | 15216 KB | Output is correct |
24 | Correct | 463 ms | 35032 KB | Output is correct |
25 | Correct | 514 ms | 47468 KB | Output is correct |
26 | Correct | 14 ms | 3832 KB | Output is correct |
27 | Correct | 325 ms | 23672 KB | Output is correct |
28 | Correct | 383 ms | 26720 KB | Output is correct |
29 | Correct | 280 ms | 22904 KB | Output is correct |
30 | Correct | 200 ms | 18808 KB | Output is correct |
31 | Correct | 33 ms | 5052 KB | Output is correct |
32 | Correct | 235 ms | 23196 KB | Output is correct |
33 | Correct | 174 ms | 25316 KB | Output is correct |
34 | Correct | 306 ms | 23464 KB | Output is correct |
35 | Correct | 11 ms | 3368 KB | Output is correct |
36 | Correct | 434 ms | 35768 KB | Output is correct |
37 | Correct | 28 ms | 4728 KB | Output is correct |
38 | Correct | 31 ms | 5108 KB | Output is correct |
39 | Correct | 107 ms | 12024 KB | Output is correct |
40 | Correct | 39 ms | 5368 KB | Output is correct |
41 | Correct | 238 ms | 21956 KB | Output is correct |
42 | Correct | 49 ms | 6788 KB | Output is correct |
43 | Correct | 255 ms | 21020 KB | Output is correct |
44 | Incorrect | 150 ms | 12396 KB | Output isn't correct |
45 | Halted | 0 ms | 0 KB | - |