#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
vector<pll> adj[1000010];
ll dist[1000010];
int main() {
ios_base :: sync_with_stdio(false); cin.tie(NULL);
ll N, M;
cin >> N >> M;
for (ll i=1; i<=N; i++) {
ll v;
cin >> v;
adj[0].push_back({i, -v});
dist[i] = 2e18;
}
for (ll i=1; i<=M; i++) {
ll u, v, c;
cin >> u >> v >> c;
adj[u].push_back({v, c});
adj[v].push_back({u, c});
}
priority_queue<pll> pq;
dist[0] = 0;
pq.push({0, 0});
while (!pq.empty()) {
ll c = -pq.top().first;
ll x = pq.top().second;
pq.pop();
if (dist[x] < c) continue;
for (auto &[y, z] : adj[x]) {
if (c + z >= dist[y]) continue;
dist[y] = c + z;
pq.push({-c-z, y});
}
}
for (ll i=1; i<=N; i++) {
cout << -dist[i] << '\n';
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
25692 KB |
Output is correct |
2 |
Correct |
6 ms |
25692 KB |
Output is correct |
3 |
Correct |
4 ms |
25692 KB |
Output is correct |
4 |
Correct |
4 ms |
25692 KB |
Output is correct |
5 |
Correct |
3 ms |
25436 KB |
Output is correct |
6 |
Correct |
3 ms |
25180 KB |
Output is correct |
7 |
Correct |
3 ms |
25436 KB |
Output is correct |
8 |
Correct |
4 ms |
25692 KB |
Output is correct |
9 |
Correct |
5 ms |
25692 KB |
Output is correct |
10 |
Correct |
5 ms |
25692 KB |
Output is correct |
11 |
Correct |
4 ms |
25664 KB |
Output is correct |
12 |
Correct |
4 ms |
25692 KB |
Output is correct |
13 |
Correct |
3 ms |
25436 KB |
Output is correct |
14 |
Correct |
3 ms |
25436 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
911 ms |
124172 KB |
Output is correct |
2 |
Correct |
817 ms |
126732 KB |
Output is correct |
3 |
Correct |
895 ms |
124148 KB |
Output is correct |
4 |
Correct |
803 ms |
126728 KB |
Output is correct |
5 |
Correct |
802 ms |
125164 KB |
Output is correct |
6 |
Correct |
849 ms |
123144 KB |
Output is correct |
7 |
Correct |
757 ms |
123048 KB |
Output is correct |
8 |
Correct |
776 ms |
121508 KB |
Output is correct |
9 |
Correct |
753 ms |
120488 KB |
Output is correct |
10 |
Correct |
756 ms |
119464 KB |
Output is correct |
11 |
Correct |
681 ms |
119200 KB |
Output is correct |
12 |
Correct |
716 ms |
116900 KB |
Output is correct |
13 |
Correct |
603 ms |
107316 KB |
Output is correct |
14 |
Correct |
598 ms |
106548 KB |
Output is correct |
15 |
Correct |
262 ms |
86344 KB |
Output is correct |
16 |
Correct |
260 ms |
85560 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
850 ms |
126620 KB |
Output is correct |
2 |
Correct |
903 ms |
123916 KB |
Output is correct |
3 |
Correct |
835 ms |
126732 KB |
Output is correct |
4 |
Correct |
868 ms |
126580 KB |
Output is correct |
5 |
Correct |
3 ms |
25428 KB |
Output is correct |
6 |
Correct |
3 ms |
25436 KB |
Output is correct |
7 |
Correct |
918 ms |
127396 KB |
Output is correct |
8 |
Correct |
891 ms |
126988 KB |
Output is correct |
9 |
Correct |
841 ms |
126812 KB |
Output is correct |
10 |
Correct |
844 ms |
126864 KB |
Output is correct |
11 |
Correct |
4 ms |
25432 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
25692 KB |
Output is correct |
2 |
Correct |
6 ms |
25692 KB |
Output is correct |
3 |
Correct |
4 ms |
25692 KB |
Output is correct |
4 |
Correct |
4 ms |
25692 KB |
Output is correct |
5 |
Correct |
3 ms |
25436 KB |
Output is correct |
6 |
Correct |
3 ms |
25180 KB |
Output is correct |
7 |
Correct |
3 ms |
25436 KB |
Output is correct |
8 |
Correct |
4 ms |
25692 KB |
Output is correct |
9 |
Correct |
5 ms |
25692 KB |
Output is correct |
10 |
Correct |
5 ms |
25692 KB |
Output is correct |
11 |
Correct |
4 ms |
25664 KB |
Output is correct |
12 |
Correct |
4 ms |
25692 KB |
Output is correct |
13 |
Correct |
3 ms |
25436 KB |
Output is correct |
14 |
Correct |
3 ms |
25436 KB |
Output is correct |
15 |
Correct |
911 ms |
124172 KB |
Output is correct |
16 |
Correct |
817 ms |
126732 KB |
Output is correct |
17 |
Correct |
895 ms |
124148 KB |
Output is correct |
18 |
Correct |
803 ms |
126728 KB |
Output is correct |
19 |
Correct |
802 ms |
125164 KB |
Output is correct |
20 |
Correct |
849 ms |
123144 KB |
Output is correct |
21 |
Correct |
757 ms |
123048 KB |
Output is correct |
22 |
Correct |
776 ms |
121508 KB |
Output is correct |
23 |
Correct |
753 ms |
120488 KB |
Output is correct |
24 |
Correct |
756 ms |
119464 KB |
Output is correct |
25 |
Correct |
681 ms |
119200 KB |
Output is correct |
26 |
Correct |
716 ms |
116900 KB |
Output is correct |
27 |
Correct |
603 ms |
107316 KB |
Output is correct |
28 |
Correct |
598 ms |
106548 KB |
Output is correct |
29 |
Correct |
262 ms |
86344 KB |
Output is correct |
30 |
Correct |
260 ms |
85560 KB |
Output is correct |
31 |
Correct |
850 ms |
126620 KB |
Output is correct |
32 |
Correct |
903 ms |
123916 KB |
Output is correct |
33 |
Correct |
835 ms |
126732 KB |
Output is correct |
34 |
Correct |
868 ms |
126580 KB |
Output is correct |
35 |
Correct |
3 ms |
25428 KB |
Output is correct |
36 |
Correct |
3 ms |
25436 KB |
Output is correct |
37 |
Correct |
918 ms |
127396 KB |
Output is correct |
38 |
Correct |
891 ms |
126988 KB |
Output is correct |
39 |
Correct |
841 ms |
126812 KB |
Output is correct |
40 |
Correct |
844 ms |
126864 KB |
Output is correct |
41 |
Correct |
4 ms |
25432 KB |
Output is correct |
42 |
Correct |
900 ms |
123916 KB |
Output is correct |
43 |
Correct |
838 ms |
126724 KB |
Output is correct |
44 |
Correct |
857 ms |
126728 KB |
Output is correct |
45 |
Correct |
893 ms |
126692 KB |
Output is correct |
46 |
Correct |
854 ms |
126724 KB |
Output is correct |
47 |
Correct |
833 ms |
122472 KB |
Output is correct |
48 |
Correct |
864 ms |
125192 KB |
Output is correct |
49 |
Correct |
748 ms |
123048 KB |
Output is correct |
50 |
Correct |
839 ms |
123224 KB |
Output is correct |
51 |
Correct |
318 ms |
90468 KB |
Output is correct |
52 |
Correct |
292 ms |
89552 KB |
Output is correct |
53 |
Correct |
181 ms |
72688 KB |
Output is correct |
54 |
Correct |
145 ms |
72020 KB |
Output is correct |
55 |
Correct |
865 ms |
126908 KB |
Output is correct |
56 |
Correct |
929 ms |
126724 KB |
Output is correct |
57 |
Correct |
333 ms |
110504 KB |
Output is correct |