# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
55212 | 2018-07-06T10:38:58 Z | Costin Andrei Oncescu(#1304) | None (JOI14_ho_t4) | C++11 | 475 ms | 18212 KB |
#include<bits/stdc++.h> using namespace std; int X, N, M, a[300009], b[300009], t[300009], maxH[100009], h[100009]; const long long INF = 1LL << 60; long long ans = -1, minD[100009]; vector < pair < int, int > > v[100009]; void read () { scanf ("%d %d %d", &N, &M, &X); for (int i=1; i<=N; i++) scanf ("%d", &h[i]); for (int i=1; i<=M; i++) scanf ("%d %d %d", &a[i], &b[i], &t[i]), v[a[i]].push_back ({b[i], t[i]}), v[b[i]].push_back ({a[i], t[i]}); } void updateAns (long long val) { if (ans == -1 || val < ans) ans = val; } priority_queue < pair < int, int > > maxHPQ; void buildMaxH () { for (int i=1; i<=N; i++) maxH[i] = -1; maxH[1] = X, maxHPQ.push ({X, 1}); while (!maxHPQ.empty ()) { auto curr = maxHPQ.top (); maxHPQ.pop (); if (maxH[curr.second] != curr.first) continue; int nod = curr.second; maxH[nod] = min (maxH[nod], h[nod]); for (auto it : v[nod]) if (maxH[it.first] < maxH[nod] - it.second) maxH[it.first] = maxH[nod] - it.second, maxHPQ.push ({maxH[it.first], it.first}); } if (maxH[N] != -1) updateAns (X - maxH[N] + h[N] - maxH[N]); } priority_queue < pair < long long, int > > PQ; void buildMinD () { for (int i=1; i<=N; i++) minD[i] = INF; minD[N] = h[N], PQ.push ({-h[N], N}); while (!PQ.empty ()) { auto curr = PQ.top (); PQ.pop (); if (minD[curr.second] != -curr.first) continue; int nod = curr.second; for (auto it : v[nod]) if (it.second <= h[it.first] && 2LL * it.second + minD[nod] < minD[it.first]) minD[it.first] = 2LL * it.second + minD[nod], PQ.push ({-minD[it.first], it.first}); } } int main () { //freopen ("input", "r", stdin); //freopen ("output", "w", stdout); read (); buildMaxH (); buildMinD (); for (int i=1; i<=N; i++) if (maxH[i] != -1) { for (auto e : v[i]) if (h[i] >= e.second && e.second >= maxH[i] && minD[e.first] < INF) updateAns (X - maxH[i] + 2LL * e.second - maxH[i] + minD[e.first]); if (minD[i] < INF) updateAns (X + minD[i]); } printf ("%lld\n", ans); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 2808 KB | Output is correct |
2 | Correct | 6 ms | 3020 KB | Output is correct |
3 | Correct | 7 ms | 3020 KB | Output is correct |
4 | Correct | 6 ms | 3020 KB | Output is correct |
5 | Correct | 6 ms | 3020 KB | Output is correct |
6 | Correct | 5 ms | 3020 KB | Output is correct |
7 | Correct | 5 ms | 3020 KB | Output is correct |
8 | Correct | 7 ms | 3096 KB | Output is correct |
9 | Correct | 9 ms | 3096 KB | Output is correct |
10 | Correct | 6 ms | 3096 KB | Output is correct |
11 | Correct | 5 ms | 3096 KB | Output is correct |
12 | Correct | 6 ms | 3136 KB | Output is correct |
13 | Correct | 6 ms | 3136 KB | Output is correct |
14 | Correct | 5 ms | 3136 KB | Output is correct |
15 | Correct | 7 ms | 3136 KB | Output is correct |
16 | Correct | 6 ms | 3136 KB | Output is correct |
17 | Correct | 5 ms | 3136 KB | Output is correct |
18 | Correct | 6 ms | 3136 KB | Output is correct |
19 | Correct | 4 ms | 3136 KB | Output is correct |
20 | Correct | 6 ms | 3136 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 341 ms | 16956 KB | Output is correct |
2 | Correct | 231 ms | 16956 KB | Output is correct |
3 | Correct | 179 ms | 16956 KB | Output is correct |
4 | Correct | 271 ms | 16956 KB | Output is correct |
5 | Correct | 198 ms | 16956 KB | Output is correct |
6 | Correct | 12 ms | 16956 KB | Output is correct |
7 | Correct | 319 ms | 16956 KB | Output is correct |
8 | Correct | 266 ms | 16956 KB | Output is correct |
9 | Correct | 242 ms | 16956 KB | Output is correct |
10 | Correct | 167 ms | 16956 KB | Output is correct |
11 | Correct | 25 ms | 16956 KB | Output is correct |
12 | Correct | 139 ms | 16956 KB | Output is correct |
13 | Correct | 107 ms | 16956 KB | Output is correct |
14 | Correct | 363 ms | 16956 KB | Output is correct |
15 | Correct | 10 ms | 16956 KB | Output is correct |
16 | Correct | 181 ms | 16956 KB | Output is correct |
17 | Correct | 22 ms | 16956 KB | Output is correct |
18 | Correct | 26 ms | 16956 KB | Output is correct |
19 | Correct | 110 ms | 16956 KB | Output is correct |
20 | Correct | 37 ms | 16956 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 2808 KB | Output is correct |
2 | Correct | 6 ms | 3020 KB | Output is correct |
3 | Correct | 7 ms | 3020 KB | Output is correct |
4 | Correct | 6 ms | 3020 KB | Output is correct |
5 | Correct | 6 ms | 3020 KB | Output is correct |
6 | Correct | 5 ms | 3020 KB | Output is correct |
7 | Correct | 5 ms | 3020 KB | Output is correct |
8 | Correct | 7 ms | 3096 KB | Output is correct |
9 | Correct | 9 ms | 3096 KB | Output is correct |
10 | Correct | 6 ms | 3096 KB | Output is correct |
11 | Correct | 5 ms | 3096 KB | Output is correct |
12 | Correct | 6 ms | 3136 KB | Output is correct |
13 | Correct | 6 ms | 3136 KB | Output is correct |
14 | Correct | 5 ms | 3136 KB | Output is correct |
15 | Correct | 7 ms | 3136 KB | Output is correct |
16 | Correct | 6 ms | 3136 KB | Output is correct |
17 | Correct | 5 ms | 3136 KB | Output is correct |
18 | Correct | 6 ms | 3136 KB | Output is correct |
19 | Correct | 4 ms | 3136 KB | Output is correct |
20 | Correct | 6 ms | 3136 KB | Output is correct |
21 | Correct | 341 ms | 16956 KB | Output is correct |
22 | Correct | 231 ms | 16956 KB | Output is correct |
23 | Correct | 179 ms | 16956 KB | Output is correct |
24 | Correct | 271 ms | 16956 KB | Output is correct |
25 | Correct | 198 ms | 16956 KB | Output is correct |
26 | Correct | 12 ms | 16956 KB | Output is correct |
27 | Correct | 319 ms | 16956 KB | Output is correct |
28 | Correct | 266 ms | 16956 KB | Output is correct |
29 | Correct | 242 ms | 16956 KB | Output is correct |
30 | Correct | 167 ms | 16956 KB | Output is correct |
31 | Correct | 25 ms | 16956 KB | Output is correct |
32 | Correct | 139 ms | 16956 KB | Output is correct |
33 | Correct | 107 ms | 16956 KB | Output is correct |
34 | Correct | 363 ms | 16956 KB | Output is correct |
35 | Correct | 10 ms | 16956 KB | Output is correct |
36 | Correct | 181 ms | 16956 KB | Output is correct |
37 | Correct | 22 ms | 16956 KB | Output is correct |
38 | Correct | 26 ms | 16956 KB | Output is correct |
39 | Correct | 110 ms | 16956 KB | Output is correct |
40 | Correct | 37 ms | 16956 KB | Output is correct |
41 | Correct | 288 ms | 16956 KB | Output is correct |
42 | Correct | 40 ms | 16956 KB | Output is correct |
43 | Correct | 185 ms | 16956 KB | Output is correct |
44 | Correct | 149 ms | 16956 KB | Output is correct |
45 | Correct | 448 ms | 17268 KB | Output is correct |
46 | Correct | 23 ms | 17268 KB | Output is correct |
47 | Correct | 424 ms | 17268 KB | Output is correct |
48 | Correct | 283 ms | 17912 KB | Output is correct |
49 | Correct | 194 ms | 17912 KB | Output is correct |
50 | Correct | 475 ms | 18212 KB | Output is correct |
51 | Correct | 60 ms | 18212 KB | Output is correct |
52 | Correct | 397 ms | 18212 KB | Output is correct |
53 | Correct | 356 ms | 18212 KB | Output is correct |
54 | Correct | 354 ms | 18212 KB | Output is correct |
55 | Correct | 370 ms | 18212 KB | Output is correct |
56 | Correct | 323 ms | 18212 KB | Output is correct |
57 | Correct | 70 ms | 18212 KB | Output is correct |
58 | Correct | 9 ms | 18212 KB | Output is correct |
59 | Correct | 324 ms | 18212 KB | Output is correct |
60 | Correct | 98 ms | 18212 KB | Output is correct |