# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1087840 |
2024-09-13T10:06:03 Z |
jonghak9028 |
None (JOI14_ho_t4) |
C++17 |
|
126 ms |
26704 KB |
/* ************************************************************************** */
/* */
/* ::: ::: ::: */
/* Problem Number: 10048 :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: js9028 <boj.kr/u/js9028> +#+ +#+ +#+ */
/* +#+ +#+ +#+ */
/* https://boj.kr/10048 #+# #+# #+# */
/* Solved: 2024/09/13 17:30:05 by js9028 ### ### ##.kr */
/* */
/* ************************************************************************** */
#include<queue>
#include<vector>
#include<iostream>
#include<array>
using namespace std;
#define fastio (ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL))
typedef long long ll;
typedef long double lld;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
const int MAXSIZE = 2000000;
const long long INF = 1e18 + 5;
const double EPSILON = 1e-14;
const ll DIV = 2000003;
const long double pi = 3.14159265358979323846264338327950288419716939937510L;
int n, m;
ll x;
ll hei[100055];
vector<pair<int, ll>> adj[100055];
ll dist[100055];
ll bfs()
{
ll ans = INF;
priority_queue<array<ll, 3>, vector<array<ll, 3>>, greater<array<ll, 3>>> pq;
pq.push({ 0, 1, x });
fill(dist, dist + n + 3, INF);
dist[1] = 0;
while (!pq.empty())
{
auto [d, cur, h] = pq.top();
pq.pop();
if (cur == n)
{
ans = min(ans, d + (hei[n] - h));
}
if (dist[cur] < d) continue;
for (auto& nxt : adj[cur])
{
ll nd = dist[cur] + nxt.second;
ll nh = h - nxt.second;
if (nh < 0)
{
nd += -nh;
nh = 0;
}
if (nh > hei[nxt.first])
{
nd += nh - hei[nxt.first];
nh = hei[nxt.first];
}
if (dist[nxt.first] <= nd || hei[cur] < nxt.second)
continue;
dist[nxt.first] = nd;
pq.push({ nd, nxt.first, nh });
}
}
return ans == INF ? -1 : ans;
}
int main()
{
fastio;
cin >> n >> m >> x;
for (int i = 1; i <= n; i++)
cin >> hei[i];
for (int i = 0; i < m; i++)
{
int a, b, c;
cin >> a >> b >> c;
adj[a].push_back({ b, c });
adj[b].push_back({ a, c });
}
cout << bfs();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2908 KB |
Output is correct |
2 |
Correct |
2 ms |
2908 KB |
Output is correct |
3 |
Correct |
2 ms |
2908 KB |
Output is correct |
4 |
Correct |
2 ms |
2908 KB |
Output is correct |
5 |
Correct |
2 ms |
2908 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 |
2 ms |
2908 KB |
Output is correct |
10 |
Correct |
2 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 |
2 ms |
2908 KB |
Output is correct |
14 |
Correct |
1 ms |
2904 KB |
Output is correct |
15 |
Correct |
2 ms |
2904 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 |
2652 KB |
Output is correct |
19 |
Correct |
1 ms |
2652 KB |
Output is correct |
20 |
Correct |
1 ms |
2908 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
123 ms |
26704 KB |
Output is correct |
2 |
Correct |
91 ms |
26020 KB |
Output is correct |
3 |
Correct |
70 ms |
14544 KB |
Output is correct |
4 |
Correct |
108 ms |
26340 KB |
Output is correct |
5 |
Correct |
82 ms |
24524 KB |
Output is correct |
6 |
Correct |
7 ms |
3928 KB |
Output is correct |
7 |
Correct |
93 ms |
25044 KB |
Output is correct |
8 |
Correct |
107 ms |
22948 KB |
Output is correct |
9 |
Correct |
98 ms |
24992 KB |
Output is correct |
10 |
Correct |
76 ms |
18772 KB |
Output is correct |
11 |
Correct |
12 ms |
4952 KB |
Output is correct |
12 |
Correct |
67 ms |
17944 KB |
Output is correct |
13 |
Correct |
26 ms |
13140 KB |
Output is correct |
14 |
Correct |
93 ms |
24660 KB |
Output is correct |
15 |
Correct |
4 ms |
3420 KB |
Output is correct |
16 |
Correct |
77 ms |
24340 KB |
Output is correct |
17 |
Correct |
10 ms |
4700 KB |
Output is correct |
18 |
Correct |
11 ms |
5140 KB |
Output is correct |
19 |
Correct |
38 ms |
12076 KB |
Output is correct |
20 |
Correct |
13 ms |
5464 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2908 KB |
Output is correct |
2 |
Correct |
2 ms |
2908 KB |
Output is correct |
3 |
Correct |
2 ms |
2908 KB |
Output is correct |
4 |
Correct |
2 ms |
2908 KB |
Output is correct |
5 |
Correct |
2 ms |
2908 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 |
2 ms |
2908 KB |
Output is correct |
10 |
Correct |
2 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 |
2 ms |
2908 KB |
Output is correct |
14 |
Correct |
1 ms |
2904 KB |
Output is correct |
15 |
Correct |
2 ms |
2904 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 |
2652 KB |
Output is correct |
19 |
Correct |
1 ms |
2652 KB |
Output is correct |
20 |
Correct |
1 ms |
2908 KB |
Output is correct |
21 |
Correct |
123 ms |
26704 KB |
Output is correct |
22 |
Correct |
91 ms |
26020 KB |
Output is correct |
23 |
Correct |
70 ms |
14544 KB |
Output is correct |
24 |
Correct |
108 ms |
26340 KB |
Output is correct |
25 |
Correct |
82 ms |
24524 KB |
Output is correct |
26 |
Correct |
7 ms |
3928 KB |
Output is correct |
27 |
Correct |
93 ms |
25044 KB |
Output is correct |
28 |
Correct |
107 ms |
22948 KB |
Output is correct |
29 |
Correct |
98 ms |
24992 KB |
Output is correct |
30 |
Correct |
76 ms |
18772 KB |
Output is correct |
31 |
Correct |
12 ms |
4952 KB |
Output is correct |
32 |
Correct |
67 ms |
17944 KB |
Output is correct |
33 |
Correct |
26 ms |
13140 KB |
Output is correct |
34 |
Correct |
93 ms |
24660 KB |
Output is correct |
35 |
Correct |
4 ms |
3420 KB |
Output is correct |
36 |
Correct |
77 ms |
24340 KB |
Output is correct |
37 |
Correct |
10 ms |
4700 KB |
Output is correct |
38 |
Correct |
11 ms |
5140 KB |
Output is correct |
39 |
Correct |
38 ms |
12076 KB |
Output is correct |
40 |
Correct |
13 ms |
5464 KB |
Output is correct |
41 |
Correct |
85 ms |
24144 KB |
Output is correct |
42 |
Correct |
18 ms |
6748 KB |
Output is correct |
43 |
Correct |
71 ms |
21332 KB |
Output is correct |
44 |
Correct |
47 ms |
11596 KB |
Output is correct |
45 |
Correct |
90 ms |
23372 KB |
Output is correct |
46 |
Correct |
8 ms |
4996 KB |
Output is correct |
47 |
Correct |
99 ms |
21492 KB |
Output is correct |
48 |
Correct |
119 ms |
25552 KB |
Output is correct |
49 |
Correct |
93 ms |
19916 KB |
Output is correct |
50 |
Correct |
97 ms |
24784 KB |
Output is correct |
51 |
Correct |
15 ms |
5980 KB |
Output is correct |
52 |
Correct |
94 ms |
25532 KB |
Output is correct |
53 |
Correct |
90 ms |
25440 KB |
Output is correct |
54 |
Correct |
95 ms |
25300 KB |
Output is correct |
55 |
Correct |
90 ms |
24452 KB |
Output is correct |
56 |
Correct |
126 ms |
25552 KB |
Output is correct |
57 |
Correct |
23 ms |
8284 KB |
Output is correct |
58 |
Correct |
3 ms |
3164 KB |
Output is correct |
59 |
Correct |
84 ms |
25488 KB |
Output is correct |
60 |
Correct |
22 ms |
8028 KB |
Output is correct |