#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 k[N];
int main() {
scanf("%d%d%d", &n, &m, &x);
assert(!x);
rep(i,1,n) scanf("%d", &h[i]);
rep(i,1,m) {
int u, v, t;
scanf("%d%d%d", &u, &v, &t);
adj[u].push_back({v,t});
adj[v].push_back({u,t});
}
fill(k,k+N,INF);
priority_queue<pair<ll,int>> pq;
k[1] = 0, pq.push({0,1});
while (not empty(pq)) {
auto [d,a] = pq.top(); pq.pop(), d=-d;
if (k[a] < d) continue;
for (auto [b,t] : adj[a]) {
if (h[a] >= t and k[b] > k[a]+2*t) {
k[b] = k[a]+2*t;
pq.push({-k[b],b});
}
}
}
if (h[n]+k[n] >= INF) puts("-1");
else printf("%lld", h[n]+k[n]);
// rep(i,1,n) dbg("%lld ", k[i]);
}
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:21:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
21 | rep(i,1,n) scanf("%d", &h[i]);
| ~~~~~^~~~~~~~~~~~~
2014_ho_t4.cpp:24:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
24 | scanf("%d%d%d", &u, &v, &t);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
3 ms |
5140 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
131 ms |
12696 KB |
Output is correct |
2 |
Correct |
103 ms |
12956 KB |
Output is correct |
3 |
Correct |
62 ms |
8496 KB |
Output is correct |
4 |
Correct |
120 ms |
13956 KB |
Output is correct |
5 |
Correct |
81 ms |
12548 KB |
Output is correct |
6 |
Correct |
5 ms |
3796 KB |
Output is correct |
7 |
Correct |
96 ms |
12472 KB |
Output is correct |
8 |
Correct |
102 ms |
11860 KB |
Output is correct |
9 |
Correct |
94 ms |
11996 KB |
Output is correct |
10 |
Correct |
78 ms |
10220 KB |
Output is correct |
11 |
Correct |
17 ms |
4436 KB |
Output is correct |
12 |
Correct |
62 ms |
9352 KB |
Output is correct |
13 |
Correct |
31 ms |
9520 KB |
Output is correct |
14 |
Correct |
103 ms |
17412 KB |
Output is correct |
15 |
Correct |
4 ms |
3796 KB |
Output is correct |
16 |
Correct |
85 ms |
16248 KB |
Output is correct |
17 |
Correct |
11 ms |
4744 KB |
Output is correct |
18 |
Correct |
13 ms |
4844 KB |
Output is correct |
19 |
Correct |
41 ms |
9604 KB |
Output is correct |
20 |
Correct |
14 ms |
4984 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
3 ms |
5140 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |