# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
991144 |
2024-06-01T12:12:57 Z |
gmroh06 |
None (JOI14_ho_t4) |
C++17 |
|
100 ms |
23504 KB |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
inline void fastio() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
}
const ll INF = 1e18;
int main() {
fastio();
ll n, m, x;
cin >> n >> m >> x;
vector<ll> h(n);
vector<vector<pll>> gr(n);
for (auto& i : h) {
cin >> i;
}
for (ll i = 0, a, b, c; i < m; i++) {
cin >> a >> b >> c;
if (h[a - 1] >= c) gr[a - 1].emplace_back(b - 1, c);
if (h[b - 1] >= c) gr[b - 1].emplace_back(a - 1, c);
}
priority_queue<pll, vector<pll>, greater<pll>> pq;
vector<ll> d(n, INF);
pq.emplace(0, 0);
d[0] = 0;
while (!pq.empty()) {
auto [dist, cur] = pq.top();
pq.pop();
if (dist > d[cur]) continue;
ll c = max(0LL, x - d[cur]), tmp;
for (auto& [nxt, cost] : gr[cur]) {
if (cost < c - h[nxt]) {
tmp = c - h[nxt];
} else if (c - h[nxt] <= cost and cost <= c) {
tmp = cost;
} else {
tmp = 2 * cost - c;
}
if (d[nxt] > d[cur] + tmp) {
d[nxt] = d[cur] + tmp;
pq.emplace(d[nxt], nxt);
}
}
}
ll ans = d.back() + h.back() + min(0LL, d.back() - x);
cout << (ans < INF ? ans : -1);
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
604 KB |
Output is correct |
3 |
Correct |
1 ms |
604 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
600 KB |
Output is correct |
9 |
Correct |
1 ms |
600 KB |
Output is correct |
10 |
Correct |
1 ms |
604 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
604 KB |
Output is correct |
13 |
Correct |
1 ms |
604 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
91 ms |
15148 KB |
Output is correct |
2 |
Correct |
79 ms |
23504 KB |
Output is correct |
3 |
Correct |
60 ms |
13772 KB |
Output is correct |
4 |
Correct |
90 ms |
22404 KB |
Output is correct |
5 |
Correct |
82 ms |
22132 KB |
Output is correct |
6 |
Correct |
3 ms |
604 KB |
Output is correct |
7 |
Correct |
50 ms |
9608 KB |
Output is correct |
8 |
Correct |
98 ms |
20948 KB |
Output is correct |
9 |
Correct |
64 ms |
10836 KB |
Output is correct |
10 |
Correct |
38 ms |
8236 KB |
Output is correct |
11 |
Correct |
10 ms |
2908 KB |
Output is correct |
12 |
Correct |
55 ms |
12848 KB |
Output is correct |
13 |
Correct |
24 ms |
10640 KB |
Output is correct |
14 |
Correct |
54 ms |
10368 KB |
Output is correct |
15 |
Correct |
3 ms |
1116 KB |
Output is correct |
16 |
Correct |
69 ms |
21648 KB |
Output is correct |
17 |
Correct |
9 ms |
2908 KB |
Output is correct |
18 |
Correct |
11 ms |
3616 KB |
Output is correct |
19 |
Correct |
23 ms |
4700 KB |
Output is correct |
20 |
Correct |
11 ms |
3676 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
604 KB |
Output is correct |
3 |
Correct |
1 ms |
604 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
600 KB |
Output is correct |
9 |
Correct |
1 ms |
600 KB |
Output is correct |
10 |
Correct |
1 ms |
604 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
604 KB |
Output is correct |
13 |
Correct |
1 ms |
604 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
344 KB |
Output is correct |
21 |
Correct |
91 ms |
15148 KB |
Output is correct |
22 |
Correct |
79 ms |
23504 KB |
Output is correct |
23 |
Correct |
60 ms |
13772 KB |
Output is correct |
24 |
Correct |
90 ms |
22404 KB |
Output is correct |
25 |
Correct |
82 ms |
22132 KB |
Output is correct |
26 |
Correct |
3 ms |
604 KB |
Output is correct |
27 |
Correct |
50 ms |
9608 KB |
Output is correct |
28 |
Correct |
98 ms |
20948 KB |
Output is correct |
29 |
Correct |
64 ms |
10836 KB |
Output is correct |
30 |
Correct |
38 ms |
8236 KB |
Output is correct |
31 |
Correct |
10 ms |
2908 KB |
Output is correct |
32 |
Correct |
55 ms |
12848 KB |
Output is correct |
33 |
Correct |
24 ms |
10640 KB |
Output is correct |
34 |
Correct |
54 ms |
10368 KB |
Output is correct |
35 |
Correct |
3 ms |
1116 KB |
Output is correct |
36 |
Correct |
69 ms |
21648 KB |
Output is correct |
37 |
Correct |
9 ms |
2908 KB |
Output is correct |
38 |
Correct |
11 ms |
3616 KB |
Output is correct |
39 |
Correct |
23 ms |
4700 KB |
Output is correct |
40 |
Correct |
11 ms |
3676 KB |
Output is correct |
41 |
Correct |
51 ms |
7436 KB |
Output is correct |
42 |
Correct |
14 ms |
5724 KB |
Output is correct |
43 |
Correct |
43 ms |
6980 KB |
Output is correct |
44 |
Correct |
41 ms |
10320 KB |
Output is correct |
45 |
Correct |
76 ms |
21296 KB |
Output is correct |
46 |
Correct |
7 ms |
5056 KB |
Output is correct |
47 |
Correct |
96 ms |
20940 KB |
Output is correct |
48 |
Correct |
97 ms |
21976 KB |
Output is correct |
49 |
Correct |
81 ms |
18644 KB |
Output is correct |
50 |
Correct |
86 ms |
22992 KB |
Output is correct |
51 |
Correct |
15 ms |
4436 KB |
Output is correct |
52 |
Correct |
80 ms |
16204 KB |
Output is correct |
53 |
Correct |
54 ms |
10068 KB |
Output is correct |
54 |
Correct |
62 ms |
11092 KB |
Output is correct |
55 |
Correct |
55 ms |
10324 KB |
Output is correct |
56 |
Correct |
100 ms |
22732 KB |
Output is correct |
57 |
Correct |
24 ms |
8140 KB |
Output is correct |
58 |
Correct |
3 ms |
1112 KB |
Output is correct |
59 |
Correct |
51 ms |
9188 KB |
Output is correct |
60 |
Correct |
21 ms |
7768 KB |
Output is correct |