# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
55161 | 2018-07-06T07:20:21 Z | 김세빈(#1527) | None (JOI14_ho_t4) | C++11 | 473 ms | 27956 KB |
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll,ll> pll; vector <pll> E[101010]; priority_queue <pll> Q; ll H[101010], D[101010], F[101010]; bool chk[101010]; ll n, s; int main() { ll m, a, b, c, i; pll p; scanf("%lld%lld%lld", &n, &m, &s); for(i=1;i<=n;i++){ scanf("%lld", H+i); D[i] = 1e18; } for(;m--;){ scanf("%lld%lld%lld", &a, &b, &c); E[a].push_back(pll(b, c)); E[b].push_back(pll(a, c)); } Q.push(pll(0, 1)); for(;!Q.empty();){ p = Q.top(); Q.pop(); if(chk[p.second]) continue; chk[p.second] = 1; D[p.second] = -p.first; for(auto t: E[p.second]){ if(!chk[t.first] && (s + p.first) >= t.second){ if(s + p.first - t.second > H[t.first]) Q.push(pll(H[t.first] - s, t.first)); else Q.push(pll(p.first - t.second, t.first)); } } } for(i=1;i<=n;i++){ if(chk[i]){ F[i] = s; for(auto t: E[i]){ if(!chk[t.first] && t.second <= H[i]){ Q.push(pll(s - D[i] * 2 - t.second * 2, t.first)); } } } } for(;!Q.empty();){ p = Q.top(); Q.pop(); if(chk[p.second]) continue; chk[p.second] = 1; F[p.second] = -p.first; for(auto t: E[p.second]){ if(!chk[t.first] && t.second <= H[p.second]){ Q.push(pll(p.first - t.second * 2, t.first)); } } } if(chk[n]) printf("%lld\n", min(D[n] + H[n] - (s - D[n]), F[n] + H[n])); else printf("-1\n"); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 2808 KB | Output is correct |
2 | Correct | 6 ms | 2916 KB | Output is correct |
3 | Correct | 9 ms | 3120 KB | Output is correct |
4 | Correct | 4 ms | 3120 KB | Output is correct |
5 | Correct | 4 ms | 3120 KB | Output is correct |
6 | Correct | 5 ms | 3120 KB | Output is correct |
7 | Correct | 6 ms | 3120 KB | Output is correct |
8 | Correct | 6 ms | 3120 KB | Output is correct |
9 | Correct | 6 ms | 3132 KB | Output is correct |
10 | Correct | 5 ms | 3176 KB | Output is correct |
11 | Correct | 4 ms | 3176 KB | Output is correct |
12 | Correct | 6 ms | 3176 KB | Output is correct |
13 | Correct | 7 ms | 3176 KB | Output is correct |
14 | Correct | 5 ms | 3176 KB | Output is correct |
15 | Correct | 6 ms | 3176 KB | Output is correct |
16 | Correct | 5 ms | 3176 KB | Output is correct |
17 | Correct | 6 ms | 3176 KB | Output is correct |
18 | Correct | 6 ms | 3176 KB | Output is correct |
19 | Correct | 5 ms | 3176 KB | Output is correct |
20 | Correct | 7 ms | 3176 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 385 ms | 21232 KB | Output is correct |
2 | Correct | 365 ms | 27956 KB | Output is correct |
3 | Correct | 207 ms | 27956 KB | Output is correct |
4 | Correct | 382 ms | 27956 KB | Output is correct |
5 | Correct | 374 ms | 27956 KB | Output is correct |
6 | Correct | 13 ms | 27956 KB | Output is correct |
7 | Correct | 321 ms | 27956 KB | Output is correct |
8 | Correct | 372 ms | 27956 KB | Output is correct |
9 | Correct | 381 ms | 27956 KB | Output is correct |
10 | Correct | 274 ms | 27956 KB | Output is correct |
11 | Correct | 33 ms | 27956 KB | Output is correct |
12 | Correct | 207 ms | 27956 KB | Output is correct |
13 | Correct | 147 ms | 27956 KB | Output is correct |
14 | Correct | 351 ms | 27956 KB | Output is correct |
15 | Correct | 13 ms | 27956 KB | Output is correct |
16 | Correct | 361 ms | 27956 KB | Output is correct |
17 | Correct | 41 ms | 27956 KB | Output is correct |
18 | Correct | 33 ms | 27956 KB | Output is correct |
19 | Correct | 130 ms | 27956 KB | Output is correct |
20 | Correct | 41 ms | 27956 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 2808 KB | Output is correct |
2 | Correct | 6 ms | 2916 KB | Output is correct |
3 | Correct | 9 ms | 3120 KB | Output is correct |
4 | Correct | 4 ms | 3120 KB | Output is correct |
5 | Correct | 4 ms | 3120 KB | Output is correct |
6 | Correct | 5 ms | 3120 KB | Output is correct |
7 | Correct | 6 ms | 3120 KB | Output is correct |
8 | Correct | 6 ms | 3120 KB | Output is correct |
9 | Correct | 6 ms | 3132 KB | Output is correct |
10 | Correct | 5 ms | 3176 KB | Output is correct |
11 | Correct | 4 ms | 3176 KB | Output is correct |
12 | Correct | 6 ms | 3176 KB | Output is correct |
13 | Correct | 7 ms | 3176 KB | Output is correct |
14 | Correct | 5 ms | 3176 KB | Output is correct |
15 | Correct | 6 ms | 3176 KB | Output is correct |
16 | Correct | 5 ms | 3176 KB | Output is correct |
17 | Correct | 6 ms | 3176 KB | Output is correct |
18 | Correct | 6 ms | 3176 KB | Output is correct |
19 | Correct | 5 ms | 3176 KB | Output is correct |
20 | Correct | 7 ms | 3176 KB | Output is correct |
21 | Correct | 385 ms | 21232 KB | Output is correct |
22 | Correct | 365 ms | 27956 KB | Output is correct |
23 | Correct | 207 ms | 27956 KB | Output is correct |
24 | Correct | 382 ms | 27956 KB | Output is correct |
25 | Correct | 374 ms | 27956 KB | Output is correct |
26 | Correct | 13 ms | 27956 KB | Output is correct |
27 | Correct | 321 ms | 27956 KB | Output is correct |
28 | Correct | 372 ms | 27956 KB | Output is correct |
29 | Correct | 381 ms | 27956 KB | Output is correct |
30 | Correct | 274 ms | 27956 KB | Output is correct |
31 | Correct | 33 ms | 27956 KB | Output is correct |
32 | Correct | 207 ms | 27956 KB | Output is correct |
33 | Correct | 147 ms | 27956 KB | Output is correct |
34 | Correct | 351 ms | 27956 KB | Output is correct |
35 | Correct | 13 ms | 27956 KB | Output is correct |
36 | Correct | 361 ms | 27956 KB | Output is correct |
37 | Correct | 41 ms | 27956 KB | Output is correct |
38 | Correct | 33 ms | 27956 KB | Output is correct |
39 | Correct | 130 ms | 27956 KB | Output is correct |
40 | Correct | 41 ms | 27956 KB | Output is correct |
41 | Correct | 284 ms | 27956 KB | Output is correct |
42 | Correct | 50 ms | 27956 KB | Output is correct |
43 | Correct | 256 ms | 27956 KB | Output is correct |
44 | Correct | 156 ms | 27956 KB | Output is correct |
45 | Correct | 392 ms | 27956 KB | Output is correct |
46 | Correct | 22 ms | 27956 KB | Output is correct |
47 | Correct | 335 ms | 27956 KB | Output is correct |
48 | Correct | 436 ms | 27956 KB | Output is correct |
49 | Correct | 339 ms | 27956 KB | Output is correct |
50 | Correct | 473 ms | 27956 KB | Output is correct |
51 | Correct | 58 ms | 27956 KB | Output is correct |
52 | Correct | 354 ms | 27956 KB | Output is correct |
53 | Correct | 356 ms | 27956 KB | Output is correct |
54 | Correct | 347 ms | 27956 KB | Output is correct |
55 | Correct | 310 ms | 27956 KB | Output is correct |
56 | Correct | 464 ms | 27956 KB | Output is correct |
57 | Correct | 120 ms | 27956 KB | Output is correct |
58 | Correct | 10 ms | 27956 KB | Output is correct |
59 | Correct | 350 ms | 27956 KB | Output is correct |
60 | Correct | 71 ms | 27956 KB | Output is correct |