#include <bits/stdc++.h>
using namespace std;
const int N = 1e5+5;
int n, m, x, h[N], mxh[N];
vector <pair <int, int>> adj[N];
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 u, v, w; cin >> u >> v >> w;
if(h[u] >= w) adj[u].emplace_back(v, w);
if(h[v] >= w) adj[v].emplace_back(u, w);
}
fill(mxh+1, mxh+1+n, -1e9);
mxh[1] = x;
priority_queue <pair <int, int>> pq;
pq.push({x, 1});
while(pq.size()) {
pair <int, int> tp = pq.top(); pq.pop();
int hu = tp.first, u = tp.second;
if(hu < mxh[u]) continue;
for(pair <int, int> i : adj[u]) {
int v = i.first, w = i.second;
int hv = min(hu-w, h[v]);
if(hv > mxh[v]) {
mxh[v] = hv;
pq.push({hv, v});
}
}
}
if(mxh[n] == (int)-1e9) cout << "-1\n";
else cout << x + h[n] - 2*mxh[n] << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2652 KB |
Output is correct |
2 |
Correct |
1 ms |
2908 KB |
Output is correct |
3 |
Correct |
1 ms |
2904 KB |
Output is correct |
4 |
Correct |
1 ms |
2652 KB |
Output is correct |
5 |
Correct |
2 ms |
2652 KB |
Output is correct |
6 |
Correct |
1 ms |
2652 KB |
Output is correct |
7 |
Correct |
1 ms |
2652 KB |
Output is correct |
8 |
Correct |
2 ms |
2908 KB |
Output is correct |
9 |
Correct |
1 ms |
2908 KB |
Output is correct |
10 |
Correct |
1 ms |
2908 KB |
Output is correct |
11 |
Correct |
1 ms |
2652 KB |
Output is correct |
12 |
Correct |
2 ms |
2908 KB |
Output is correct |
13 |
Correct |
1 ms |
2908 KB |
Output is correct |
14 |
Correct |
1 ms |
2904 KB |
Output is correct |
15 |
Correct |
1 ms |
2652 KB |
Output is correct |
16 |
Correct |
1 ms |
2652 KB |
Output is correct |
17 |
Correct |
1 ms |
2652 KB |
Output is correct |
18 |
Correct |
1 ms |
2824 KB |
Output is correct |
19 |
Correct |
1 ms |
2652 KB |
Output is correct |
20 |
Correct |
1 ms |
2904 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
80 ms |
13140 KB |
Output is correct |
2 |
Correct |
73 ms |
16848 KB |
Output is correct |
3 |
Correct |
52 ms |
10832 KB |
Output is correct |
4 |
Correct |
85 ms |
16060 KB |
Output is correct |
5 |
Correct |
67 ms |
15824 KB |
Output is correct |
6 |
Correct |
4 ms |
2904 KB |
Output is correct |
7 |
Correct |
55 ms |
8788 KB |
Output is correct |
8 |
Correct |
88 ms |
15308 KB |
Output is correct |
9 |
Correct |
60 ms |
10576 KB |
Output is correct |
10 |
Correct |
37 ms |
7508 KB |
Output is correct |
11 |
Correct |
10 ms |
4188 KB |
Output is correct |
12 |
Correct |
51 ms |
10904 KB |
Output is correct |
13 |
Correct |
26 ms |
8536 KB |
Output is correct |
14 |
Correct |
58 ms |
9040 KB |
Output is correct |
15 |
Incorrect |
3 ms |
3160 KB |
Output isn't correct |
16 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2652 KB |
Output is correct |
2 |
Correct |
1 ms |
2908 KB |
Output is correct |
3 |
Correct |
1 ms |
2904 KB |
Output is correct |
4 |
Correct |
1 ms |
2652 KB |
Output is correct |
5 |
Correct |
2 ms |
2652 KB |
Output is correct |
6 |
Correct |
1 ms |
2652 KB |
Output is correct |
7 |
Correct |
1 ms |
2652 KB |
Output is correct |
8 |
Correct |
2 ms |
2908 KB |
Output is correct |
9 |
Correct |
1 ms |
2908 KB |
Output is correct |
10 |
Correct |
1 ms |
2908 KB |
Output is correct |
11 |
Correct |
1 ms |
2652 KB |
Output is correct |
12 |
Correct |
2 ms |
2908 KB |
Output is correct |
13 |
Correct |
1 ms |
2908 KB |
Output is correct |
14 |
Correct |
1 ms |
2904 KB |
Output is correct |
15 |
Correct |
1 ms |
2652 KB |
Output is correct |
16 |
Correct |
1 ms |
2652 KB |
Output is correct |
17 |
Correct |
1 ms |
2652 KB |
Output is correct |
18 |
Correct |
1 ms |
2824 KB |
Output is correct |
19 |
Correct |
1 ms |
2652 KB |
Output is correct |
20 |
Correct |
1 ms |
2904 KB |
Output is correct |
21 |
Correct |
80 ms |
13140 KB |
Output is correct |
22 |
Correct |
73 ms |
16848 KB |
Output is correct |
23 |
Correct |
52 ms |
10832 KB |
Output is correct |
24 |
Correct |
85 ms |
16060 KB |
Output is correct |
25 |
Correct |
67 ms |
15824 KB |
Output is correct |
26 |
Correct |
4 ms |
2904 KB |
Output is correct |
27 |
Correct |
55 ms |
8788 KB |
Output is correct |
28 |
Correct |
88 ms |
15308 KB |
Output is correct |
29 |
Correct |
60 ms |
10576 KB |
Output is correct |
30 |
Correct |
37 ms |
7508 KB |
Output is correct |
31 |
Correct |
10 ms |
4188 KB |
Output is correct |
32 |
Correct |
51 ms |
10904 KB |
Output is correct |
33 |
Correct |
26 ms |
8536 KB |
Output is correct |
34 |
Correct |
58 ms |
9040 KB |
Output is correct |
35 |
Incorrect |
3 ms |
3160 KB |
Output isn't correct |
36 |
Halted |
0 ms |
0 KB |
- |