# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
684463 |
2023-01-21T09:54:38 Z |
JooDdae |
None (JOI14_ho_t4) |
C++17 |
|
199 ms |
25292 KB |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e18;
int n, m, X;
ll h[100100];
vector<array<int, 2>> v[300300];
ll d1[100100];
priority_queue<array<ll, 2>> pq;
ll d2[100100];
int main(){
cin.tie(0)->sync_with_stdio(0);
cin >> n >> m >> X;
for(int i=1;i<=n;i++) cin >> h[i];
for(int i=1;i<=m;i++) {
int a, b, c; cin >> a >> b >> c;
v[a].push_back({b, c}), v[b].push_back({a, c});
}
memset(d1, -1, sizeof d1);
d1[1] = X; pq.push({X, 1});
while(!pq.empty()) {
auto [c, u] = pq.top(); pq.pop();
if(c < d1[u]) continue;
for(auto [x, y] : v[u]) if(d1[x] < min(h[x], c-y)) d1[x] = min(h[x], c-y), pq.push({d1[x], x});
}
if(d1[n] > -1) return cout << X-d1[n] + h[n]-d1[n], 0;
for(int i=1;i<=n;i++) d2[i] = (d1[i] < 0 ? INF : X);
for(int i=1;i<=n;i++) if(d1[i] > -1) {
for(auto [x, y] : v[i]) if(h[i] >= y && y > d1[i]) d2[x] = min(d2[x], X-d1[i] + y-d1[i] + y);
}
for(int i=1;i<=n;i++) if(d2[i] < INF) pq.push({-d2[i], i});
while(!pq.empty()) {
auto [c, u] = pq.top(); pq.pop();
if(-c > d2[u]) continue;
for(auto [x, y] : v[u]) if(h[u] >= y && y+y-c < d2[x]) d2[x] = y+y-c, pq.push({-d2[x], x});
}
ll ans = d2[n] + h[n];
cout << (ans >= INF ? -1 : ans);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
8148 KB |
Output is correct |
2 |
Correct |
6 ms |
8276 KB |
Output is correct |
3 |
Correct |
6 ms |
8304 KB |
Output is correct |
4 |
Correct |
5 ms |
8172 KB |
Output is correct |
5 |
Correct |
6 ms |
8148 KB |
Output is correct |
6 |
Correct |
4 ms |
8148 KB |
Output is correct |
7 |
Correct |
4 ms |
8164 KB |
Output is correct |
8 |
Correct |
5 ms |
8276 KB |
Output is correct |
9 |
Correct |
5 ms |
8276 KB |
Output is correct |
10 |
Correct |
7 ms |
8228 KB |
Output is correct |
11 |
Correct |
4 ms |
8156 KB |
Output is correct |
12 |
Correct |
5 ms |
8276 KB |
Output is correct |
13 |
Correct |
5 ms |
8276 KB |
Output is correct |
14 |
Correct |
4 ms |
8148 KB |
Output is correct |
15 |
Correct |
5 ms |
8276 KB |
Output is correct |
16 |
Correct |
5 ms |
8148 KB |
Output is correct |
17 |
Correct |
4 ms |
8164 KB |
Output is correct |
18 |
Correct |
4 ms |
8148 KB |
Output is correct |
19 |
Correct |
4 ms |
8164 KB |
Output is correct |
20 |
Correct |
5 ms |
8148 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
190 ms |
25292 KB |
Output is correct |
2 |
Correct |
111 ms |
23080 KB |
Output is correct |
3 |
Correct |
92 ms |
17432 KB |
Output is correct |
4 |
Correct |
139 ms |
23820 KB |
Output is correct |
5 |
Correct |
115 ms |
21992 KB |
Output is correct |
6 |
Correct |
9 ms |
8924 KB |
Output is correct |
7 |
Correct |
149 ms |
23708 KB |
Output is correct |
8 |
Correct |
181 ms |
22576 KB |
Output is correct |
9 |
Correct |
153 ms |
23484 KB |
Output is correct |
10 |
Correct |
96 ms |
19856 KB |
Output is correct |
11 |
Correct |
16 ms |
9812 KB |
Output is correct |
12 |
Correct |
84 ms |
18272 KB |
Output is correct |
13 |
Correct |
45 ms |
14184 KB |
Output is correct |
14 |
Correct |
171 ms |
23408 KB |
Output is correct |
15 |
Correct |
8 ms |
8660 KB |
Output is correct |
16 |
Correct |
102 ms |
21428 KB |
Output is correct |
17 |
Correct |
16 ms |
9708 KB |
Output is correct |
18 |
Correct |
18 ms |
10084 KB |
Output is correct |
19 |
Correct |
63 ms |
14844 KB |
Output is correct |
20 |
Correct |
20 ms |
10192 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
8148 KB |
Output is correct |
2 |
Correct |
6 ms |
8276 KB |
Output is correct |
3 |
Correct |
6 ms |
8304 KB |
Output is correct |
4 |
Correct |
5 ms |
8172 KB |
Output is correct |
5 |
Correct |
6 ms |
8148 KB |
Output is correct |
6 |
Correct |
4 ms |
8148 KB |
Output is correct |
7 |
Correct |
4 ms |
8164 KB |
Output is correct |
8 |
Correct |
5 ms |
8276 KB |
Output is correct |
9 |
Correct |
5 ms |
8276 KB |
Output is correct |
10 |
Correct |
7 ms |
8228 KB |
Output is correct |
11 |
Correct |
4 ms |
8156 KB |
Output is correct |
12 |
Correct |
5 ms |
8276 KB |
Output is correct |
13 |
Correct |
5 ms |
8276 KB |
Output is correct |
14 |
Correct |
4 ms |
8148 KB |
Output is correct |
15 |
Correct |
5 ms |
8276 KB |
Output is correct |
16 |
Correct |
5 ms |
8148 KB |
Output is correct |
17 |
Correct |
4 ms |
8164 KB |
Output is correct |
18 |
Correct |
4 ms |
8148 KB |
Output is correct |
19 |
Correct |
4 ms |
8164 KB |
Output is correct |
20 |
Correct |
5 ms |
8148 KB |
Output is correct |
21 |
Correct |
190 ms |
25292 KB |
Output is correct |
22 |
Correct |
111 ms |
23080 KB |
Output is correct |
23 |
Correct |
92 ms |
17432 KB |
Output is correct |
24 |
Correct |
139 ms |
23820 KB |
Output is correct |
25 |
Correct |
115 ms |
21992 KB |
Output is correct |
26 |
Correct |
9 ms |
8924 KB |
Output is correct |
27 |
Correct |
149 ms |
23708 KB |
Output is correct |
28 |
Correct |
181 ms |
22576 KB |
Output is correct |
29 |
Correct |
153 ms |
23484 KB |
Output is correct |
30 |
Correct |
96 ms |
19856 KB |
Output is correct |
31 |
Correct |
16 ms |
9812 KB |
Output is correct |
32 |
Correct |
84 ms |
18272 KB |
Output is correct |
33 |
Correct |
45 ms |
14184 KB |
Output is correct |
34 |
Correct |
171 ms |
23408 KB |
Output is correct |
35 |
Correct |
8 ms |
8660 KB |
Output is correct |
36 |
Correct |
102 ms |
21428 KB |
Output is correct |
37 |
Correct |
16 ms |
9708 KB |
Output is correct |
38 |
Correct |
18 ms |
10084 KB |
Output is correct |
39 |
Correct |
63 ms |
14844 KB |
Output is correct |
40 |
Correct |
20 ms |
10192 KB |
Output is correct |
41 |
Correct |
110 ms |
22404 KB |
Output is correct |
42 |
Correct |
26 ms |
11748 KB |
Output is correct |
43 |
Correct |
110 ms |
20372 KB |
Output is correct |
44 |
Correct |
63 ms |
14528 KB |
Output is correct |
45 |
Correct |
112 ms |
21180 KB |
Output is correct |
46 |
Correct |
12 ms |
9576 KB |
Output is correct |
47 |
Correct |
141 ms |
21240 KB |
Output is correct |
48 |
Correct |
199 ms |
23880 KB |
Output is correct |
49 |
Correct |
120 ms |
20380 KB |
Output is correct |
50 |
Correct |
126 ms |
22136 KB |
Output is correct |
51 |
Correct |
26 ms |
10668 KB |
Output is correct |
52 |
Correct |
127 ms |
23360 KB |
Output is correct |
53 |
Correct |
140 ms |
24136 KB |
Output is correct |
54 |
Correct |
135 ms |
23428 KB |
Output is correct |
55 |
Correct |
155 ms |
23168 KB |
Output is correct |
56 |
Correct |
151 ms |
23748 KB |
Output is correct |
57 |
Correct |
33 ms |
12620 KB |
Output is correct |
58 |
Correct |
6 ms |
8532 KB |
Output is correct |
59 |
Correct |
139 ms |
23640 KB |
Output is correct |
60 |
Correct |
39 ms |
12496 KB |
Output is correct |