#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...)
#endif
using pii=array<int,2>;
const int N=1000005;
int n,m,a[N],d[N];
vector<pii> g[N];
priority_queue<pii> pq;
int main(){
ios::sync_with_stdio(false); cin.tie(0);
cin>>n>>m;
for(int i=1;i<=n;i++){
cin>>a[i];
d[i]=a[i];
}
for(int u,v,w,i=1;i<=m;i++){
cin>>u>>v>>w;
g[u].push_back({v,w});
g[v].push_back({u,w});
}
for(int i=1;i<=n;i++) pq.push({d[i],i});
while(pq.size()){
auto [di,u]=pq.top(); pq.pop();
if(d[u]!=di) continue;
for(auto [v,w]: g[u]) if(d[v]<d[u]-w){
d[v]=d[u]-w;
pq.push({d[v],v});
}
}
for(int i=1;i<=n;i++) cout<<d[i]<<"\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
24104 KB |
Output is correct |
2 |
Correct |
10 ms |
24220 KB |
Output is correct |
3 |
Correct |
10 ms |
24152 KB |
Output is correct |
4 |
Correct |
9 ms |
24100 KB |
Output is correct |
5 |
Correct |
8 ms |
23920 KB |
Output is correct |
6 |
Correct |
9 ms |
23900 KB |
Output is correct |
7 |
Correct |
8 ms |
23952 KB |
Output is correct |
8 |
Correct |
10 ms |
24156 KB |
Output is correct |
9 |
Correct |
10 ms |
24156 KB |
Output is correct |
10 |
Correct |
10 ms |
24156 KB |
Output is correct |
11 |
Correct |
8 ms |
23900 KB |
Output is correct |
12 |
Correct |
9 ms |
23952 KB |
Output is correct |
13 |
Correct |
9 ms |
23900 KB |
Output is correct |
14 |
Correct |
8 ms |
23788 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
933 ms |
111272 KB |
Output is correct |
2 |
Correct |
836 ms |
111284 KB |
Output is correct |
3 |
Correct |
895 ms |
87112 KB |
Output is correct |
4 |
Correct |
848 ms |
86064 KB |
Output is correct |
5 |
Correct |
788 ms |
84540 KB |
Output is correct |
6 |
Correct |
854 ms |
84400 KB |
Output is correct |
7 |
Correct |
737 ms |
81836 KB |
Output is correct |
8 |
Correct |
822 ms |
81492 KB |
Output is correct |
9 |
Correct |
680 ms |
78260 KB |
Output is correct |
10 |
Correct |
753 ms |
77992 KB |
Output is correct |
11 |
Correct |
666 ms |
74424 KB |
Output is correct |
12 |
Correct |
666 ms |
74416 KB |
Output is correct |
13 |
Correct |
550 ms |
70580 KB |
Output is correct |
14 |
Correct |
641 ms |
70808 KB |
Output is correct |
15 |
Correct |
274 ms |
54512 KB |
Output is correct |
16 |
Correct |
247 ms |
54212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
824 ms |
85984 KB |
Output is correct |
2 |
Correct |
932 ms |
86188 KB |
Output is correct |
3 |
Correct |
823 ms |
86080 KB |
Output is correct |
4 |
Correct |
810 ms |
86096 KB |
Output is correct |
5 |
Correct |
9 ms |
23900 KB |
Output is correct |
6 |
Correct |
8 ms |
23948 KB |
Output is correct |
7 |
Correct |
901 ms |
86500 KB |
Output is correct |
8 |
Correct |
871 ms |
86492 KB |
Output is correct |
9 |
Correct |
845 ms |
86068 KB |
Output is correct |
10 |
Correct |
857 ms |
86144 KB |
Output is correct |
11 |
Correct |
9 ms |
23896 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
24104 KB |
Output is correct |
2 |
Correct |
10 ms |
24220 KB |
Output is correct |
3 |
Correct |
10 ms |
24152 KB |
Output is correct |
4 |
Correct |
9 ms |
24100 KB |
Output is correct |
5 |
Correct |
8 ms |
23920 KB |
Output is correct |
6 |
Correct |
9 ms |
23900 KB |
Output is correct |
7 |
Correct |
8 ms |
23952 KB |
Output is correct |
8 |
Correct |
10 ms |
24156 KB |
Output is correct |
9 |
Correct |
10 ms |
24156 KB |
Output is correct |
10 |
Correct |
10 ms |
24156 KB |
Output is correct |
11 |
Correct |
8 ms |
23900 KB |
Output is correct |
12 |
Correct |
9 ms |
23952 KB |
Output is correct |
13 |
Correct |
9 ms |
23900 KB |
Output is correct |
14 |
Correct |
8 ms |
23788 KB |
Output is correct |
15 |
Correct |
933 ms |
111272 KB |
Output is correct |
16 |
Correct |
836 ms |
111284 KB |
Output is correct |
17 |
Correct |
895 ms |
87112 KB |
Output is correct |
18 |
Correct |
848 ms |
86064 KB |
Output is correct |
19 |
Correct |
788 ms |
84540 KB |
Output is correct |
20 |
Correct |
854 ms |
84400 KB |
Output is correct |
21 |
Correct |
737 ms |
81836 KB |
Output is correct |
22 |
Correct |
822 ms |
81492 KB |
Output is correct |
23 |
Correct |
680 ms |
78260 KB |
Output is correct |
24 |
Correct |
753 ms |
77992 KB |
Output is correct |
25 |
Correct |
666 ms |
74424 KB |
Output is correct |
26 |
Correct |
666 ms |
74416 KB |
Output is correct |
27 |
Correct |
550 ms |
70580 KB |
Output is correct |
28 |
Correct |
641 ms |
70808 KB |
Output is correct |
29 |
Correct |
274 ms |
54512 KB |
Output is correct |
30 |
Correct |
247 ms |
54212 KB |
Output is correct |
31 |
Correct |
824 ms |
85984 KB |
Output is correct |
32 |
Correct |
932 ms |
86188 KB |
Output is correct |
33 |
Correct |
823 ms |
86080 KB |
Output is correct |
34 |
Correct |
810 ms |
86096 KB |
Output is correct |
35 |
Correct |
9 ms |
23900 KB |
Output is correct |
36 |
Correct |
8 ms |
23948 KB |
Output is correct |
37 |
Correct |
901 ms |
86500 KB |
Output is correct |
38 |
Correct |
871 ms |
86492 KB |
Output is correct |
39 |
Correct |
845 ms |
86068 KB |
Output is correct |
40 |
Correct |
857 ms |
86144 KB |
Output is correct |
41 |
Correct |
9 ms |
23896 KB |
Output is correct |
42 |
Correct |
885 ms |
100028 KB |
Output is correct |
43 |
Correct |
828 ms |
119108 KB |
Output is correct |
44 |
Correct |
855 ms |
103852 KB |
Output is correct |
45 |
Correct |
844 ms |
111936 KB |
Output is correct |
46 |
Correct |
853 ms |
102320 KB |
Output is correct |
47 |
Correct |
844 ms |
97196 KB |
Output is correct |
48 |
Correct |
852 ms |
107152 KB |
Output is correct |
49 |
Correct |
751 ms |
93516 KB |
Output is correct |
50 |
Correct |
800 ms |
96428 KB |
Output is correct |
51 |
Correct |
295 ms |
64708 KB |
Output is correct |
52 |
Correct |
282 ms |
56324 KB |
Output is correct |
53 |
Correct |
148 ms |
49176 KB |
Output is correct |
54 |
Correct |
152 ms |
52324 KB |
Output is correct |
55 |
Correct |
913 ms |
106792 KB |
Output is correct |
56 |
Correct |
904 ms |
88868 KB |
Output is correct |
57 |
Correct |
342 ms |
79980 KB |
Output is correct |