# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
768375 |
2023-06-28T02:50:54 Z |
hgmhc |
None (JOI14_ho_t4) |
C++17 |
|
126 ms |
17280 KB |
#include <bits/stdc++.h>
#define rep(i,a,b) for (auto i = (a); i <= (b); ++i)
#define Mup(x,y) x = max(x,y)
#define mup(x,y) x = min(x,y)
#define all(x) begin(x),end(x)
#define per(i,a,b) for (auto i = (b); i >= (a); --i)
using namespace std;
using ll = long long;
using ii = pair<int,int>;
#define dbg(...) fprintf(stderr,__VA_ARGS__)
const ll INF = 1e18;
const int N = 1e5+3;
int n, m, x, h[N];
vector<ii> adj[N];
ll dist[N];
int main() {
scanf("%d%d%d", &n, &m, &x);
rep(i,1,n) scanf("%d", &h[i]);
rep(i,1,m) {
int u, v, t;
scanf("%d%d%d", &u, &v, &t);
if (h[u] >= t) adj[u].push_back({v,t});
if (h[v] >= t) adj[v].push_back({u,t});
}
fill(dist,dist+N,INF);
priority_queue<pair<ll,int>> pq;
dist[1] = 0, pq.push({0,1});
while (not empty(pq)) {
auto [d,a] = pq.top(); pq.pop(), d=-d;
if (dist[a] < d) continue;
for (auto [b,w] : adj[a]) {
if (dist[a] < x) {
if (x-dist[a] >= w) {
if (dist[b] > max(dist[a]+w,0LL+x-h[b])) {
dist[b] = max(dist[a]+w,0LL+x-h[b]);
pq.push({-dist[b],b});
}
} else {
if (dist[b] > dist[a]+w+w-(x-dist[a])) {
dist[b] = dist[a]+w+w-(x-dist[a]);
pq.push({-dist[b],b});
}
}
}
else if (dist[b] > dist[a]+2*w) {
dist[b] = dist[a]+2*w;
pq.push({-dist[b],b});
}
}
}
if (dist[n] < x) printf("%lld", h[n]-(x-dist[n]) + dist[n]);
else if (h[n]+dist[n] >= INF) puts("-1");
else printf("%lld", h[n]+dist[n]);
}
Compilation message
2014_ho_t4.cpp: In function 'int main()':
2014_ho_t4.cpp:19:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
19 | scanf("%d%d%d", &n, &m, &x);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~
2014_ho_t4.cpp:20:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
20 | rep(i,1,n) scanf("%d", &h[i]);
| ~~~~~^~~~~~~~~~~~~
2014_ho_t4.cpp:23:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
23 | scanf("%d%d%d", &u, &v, &t);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3412 KB |
Output is correct |
2 |
Correct |
2 ms |
3412 KB |
Output is correct |
3 |
Correct |
3 ms |
3412 KB |
Output is correct |
4 |
Correct |
2 ms |
3412 KB |
Output is correct |
5 |
Correct |
2 ms |
3412 KB |
Output is correct |
6 |
Correct |
2 ms |
3412 KB |
Output is correct |
7 |
Correct |
2 ms |
3412 KB |
Output is correct |
8 |
Correct |
3 ms |
3412 KB |
Output is correct |
9 |
Correct |
2 ms |
3412 KB |
Output is correct |
10 |
Correct |
2 ms |
3416 KB |
Output is correct |
11 |
Correct |
2 ms |
3412 KB |
Output is correct |
12 |
Correct |
2 ms |
3412 KB |
Output is correct |
13 |
Correct |
2 ms |
3412 KB |
Output is correct |
14 |
Correct |
2 ms |
3412 KB |
Output is correct |
15 |
Correct |
2 ms |
3412 KB |
Output is correct |
16 |
Correct |
2 ms |
3412 KB |
Output is correct |
17 |
Correct |
2 ms |
3412 KB |
Output is correct |
18 |
Correct |
2 ms |
3412 KB |
Output is correct |
19 |
Correct |
2 ms |
3412 KB |
Output is correct |
20 |
Correct |
2 ms |
3412 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
104 ms |
6780 KB |
Output is correct |
2 |
Correct |
94 ms |
12964 KB |
Output is correct |
3 |
Correct |
63 ms |
8272 KB |
Output is correct |
4 |
Correct |
107 ms |
12960 KB |
Output is correct |
5 |
Correct |
83 ms |
12484 KB |
Output is correct |
6 |
Correct |
5 ms |
3412 KB |
Output is correct |
7 |
Correct |
60 ms |
3788 KB |
Output is correct |
8 |
Correct |
100 ms |
11284 KB |
Output is correct |
9 |
Correct |
69 ms |
5004 KB |
Output is correct |
10 |
Correct |
44 ms |
4044 KB |
Output is correct |
11 |
Correct |
12 ms |
4420 KB |
Output is correct |
12 |
Correct |
60 ms |
7860 KB |
Output is correct |
13 |
Correct |
29 ms |
7820 KB |
Output is correct |
14 |
Correct |
62 ms |
4468 KB |
Output is correct |
15 |
Correct |
5 ms |
3540 KB |
Output is correct |
16 |
Correct |
81 ms |
12408 KB |
Output is correct |
17 |
Correct |
10 ms |
4104 KB |
Output is correct |
18 |
Correct |
12 ms |
4176 KB |
Output is correct |
19 |
Correct |
27 ms |
3584 KB |
Output is correct |
20 |
Correct |
13 ms |
4432 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3412 KB |
Output is correct |
2 |
Correct |
2 ms |
3412 KB |
Output is correct |
3 |
Correct |
3 ms |
3412 KB |
Output is correct |
4 |
Correct |
2 ms |
3412 KB |
Output is correct |
5 |
Correct |
2 ms |
3412 KB |
Output is correct |
6 |
Correct |
2 ms |
3412 KB |
Output is correct |
7 |
Correct |
2 ms |
3412 KB |
Output is correct |
8 |
Correct |
3 ms |
3412 KB |
Output is correct |
9 |
Correct |
2 ms |
3412 KB |
Output is correct |
10 |
Correct |
2 ms |
3416 KB |
Output is correct |
11 |
Correct |
2 ms |
3412 KB |
Output is correct |
12 |
Correct |
2 ms |
3412 KB |
Output is correct |
13 |
Correct |
2 ms |
3412 KB |
Output is correct |
14 |
Correct |
2 ms |
3412 KB |
Output is correct |
15 |
Correct |
2 ms |
3412 KB |
Output is correct |
16 |
Correct |
2 ms |
3412 KB |
Output is correct |
17 |
Correct |
2 ms |
3412 KB |
Output is correct |
18 |
Correct |
2 ms |
3412 KB |
Output is correct |
19 |
Correct |
2 ms |
3412 KB |
Output is correct |
20 |
Correct |
2 ms |
3412 KB |
Output is correct |
21 |
Correct |
104 ms |
6780 KB |
Output is correct |
22 |
Correct |
94 ms |
12964 KB |
Output is correct |
23 |
Correct |
63 ms |
8272 KB |
Output is correct |
24 |
Correct |
107 ms |
12960 KB |
Output is correct |
25 |
Correct |
83 ms |
12484 KB |
Output is correct |
26 |
Correct |
5 ms |
3412 KB |
Output is correct |
27 |
Correct |
60 ms |
3788 KB |
Output is correct |
28 |
Correct |
100 ms |
11284 KB |
Output is correct |
29 |
Correct |
69 ms |
5004 KB |
Output is correct |
30 |
Correct |
44 ms |
4044 KB |
Output is correct |
31 |
Correct |
12 ms |
4420 KB |
Output is correct |
32 |
Correct |
60 ms |
7860 KB |
Output is correct |
33 |
Correct |
29 ms |
7820 KB |
Output is correct |
34 |
Correct |
62 ms |
4468 KB |
Output is correct |
35 |
Correct |
5 ms |
3540 KB |
Output is correct |
36 |
Correct |
81 ms |
12408 KB |
Output is correct |
37 |
Correct |
10 ms |
4104 KB |
Output is correct |
38 |
Correct |
12 ms |
4176 KB |
Output is correct |
39 |
Correct |
27 ms |
3584 KB |
Output is correct |
40 |
Correct |
13 ms |
4432 KB |
Output is correct |
41 |
Correct |
63 ms |
9676 KB |
Output is correct |
42 |
Correct |
18 ms |
5388 KB |
Output is correct |
43 |
Correct |
55 ms |
8008 KB |
Output is correct |
44 |
Correct |
50 ms |
9468 KB |
Output is correct |
45 |
Correct |
86 ms |
16232 KB |
Output is correct |
46 |
Correct |
9 ms |
4436 KB |
Output is correct |
47 |
Correct |
94 ms |
15992 KB |
Output is correct |
48 |
Correct |
126 ms |
16412 KB |
Output is correct |
49 |
Correct |
90 ms |
14000 KB |
Output is correct |
50 |
Correct |
95 ms |
17280 KB |
Output is correct |
51 |
Correct |
16 ms |
5444 KB |
Output is correct |
52 |
Correct |
90 ms |
14240 KB |
Output is correct |
53 |
Correct |
63 ms |
9680 KB |
Output is correct |
54 |
Correct |
78 ms |
10800 KB |
Output is correct |
55 |
Correct |
65 ms |
9412 KB |
Output is correct |
56 |
Correct |
112 ms |
16692 KB |
Output is correct |
57 |
Correct |
25 ms |
6732 KB |
Output is correct |
58 |
Correct |
4 ms |
3668 KB |
Output is correct |
59 |
Correct |
62 ms |
9316 KB |
Output is correct |
60 |
Correct |
25 ms |
6584 KB |
Output is correct |