#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
using lint = long long;
using vint = vector<int>;
using pii = pair<int,int>;
const int MAX_N=1000010;
struct Obj
{
int v;lint d;
bool operator < (const Obj &o) const
{
return d<o.d;
}
};
int n,m;
vector<Obj> edge[MAX_N];
lint val[MAX_N];
priority_queue<Obj> pq;
int main()
{
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
cin >> n >> m;
for(int i=1;i<=n;i++)
{
cin >> val[i];
pq.push({i,val[i]});
}
for(int i=0;i<m;i++)
{
int u,v,d;
cin >> u >> v >> d;
edge[u].push_back({v,d});
edge[v].push_back({u,d});
}
while(!pq.empty())
{
Obj p=pq.top();
pq.pop();
if(p.d!=val[p.v])continue;
for(auto e : edge[p.v])
if(val[e.v]<p.d-e.d)
{
val[e.v]=p.d-e.d;
pq.push({e.v,p.d-e.d});
}
}
for(int i=1;i<=n;i++)
cout << val[i] << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
24152 KB |
Output is correct |
2 |
Correct |
9 ms |
24156 KB |
Output is correct |
3 |
Correct |
9 ms |
24156 KB |
Output is correct |
4 |
Correct |
13 ms |
24268 KB |
Output is correct |
5 |
Correct |
9 ms |
23896 KB |
Output is correct |
6 |
Correct |
9 ms |
23900 KB |
Output is correct |
7 |
Correct |
11 ms |
23896 KB |
Output is correct |
8 |
Correct |
9 ms |
24300 KB |
Output is correct |
9 |
Correct |
10 ms |
24220 KB |
Output is correct |
10 |
Correct |
10 ms |
24156 KB |
Output is correct |
11 |
Correct |
8 ms |
24220 KB |
Output is correct |
12 |
Correct |
9 ms |
24208 KB |
Output is correct |
13 |
Correct |
8 ms |
23900 KB |
Output is correct |
14 |
Correct |
8 ms |
23900 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1031 ms |
130444 KB |
Output is correct |
2 |
Correct |
903 ms |
133200 KB |
Output is correct |
3 |
Correct |
942 ms |
109216 KB |
Output is correct |
4 |
Correct |
896 ms |
111008 KB |
Output is correct |
5 |
Correct |
821 ms |
110756 KB |
Output is correct |
6 |
Correct |
891 ms |
108204 KB |
Output is correct |
7 |
Correct |
792 ms |
108048 KB |
Output is correct |
8 |
Correct |
826 ms |
106264 KB |
Output is correct |
9 |
Correct |
801 ms |
104600 KB |
Output is correct |
10 |
Correct |
786 ms |
103580 KB |
Output is correct |
11 |
Correct |
718 ms |
100732 KB |
Output is correct |
12 |
Correct |
740 ms |
100060 KB |
Output is correct |
13 |
Correct |
635 ms |
97756 KB |
Output is correct |
14 |
Correct |
657 ms |
97460 KB |
Output is correct |
15 |
Correct |
271 ms |
80840 KB |
Output is correct |
16 |
Correct |
274 ms |
80832 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
921 ms |
111004 KB |
Output is correct |
2 |
Correct |
956 ms |
108316 KB |
Output is correct |
3 |
Correct |
964 ms |
111008 KB |
Output is correct |
4 |
Correct |
1000 ms |
110992 KB |
Output is correct |
5 |
Correct |
8 ms |
23900 KB |
Output is correct |
6 |
Correct |
7 ms |
23896 KB |
Output is correct |
7 |
Correct |
1072 ms |
111632 KB |
Output is correct |
8 |
Correct |
1076 ms |
111260 KB |
Output is correct |
9 |
Correct |
984 ms |
111020 KB |
Output is correct |
10 |
Correct |
1024 ms |
111040 KB |
Output is correct |
11 |
Correct |
10 ms |
23896 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
24152 KB |
Output is correct |
2 |
Correct |
9 ms |
24156 KB |
Output is correct |
3 |
Correct |
9 ms |
24156 KB |
Output is correct |
4 |
Correct |
13 ms |
24268 KB |
Output is correct |
5 |
Correct |
9 ms |
23896 KB |
Output is correct |
6 |
Correct |
9 ms |
23900 KB |
Output is correct |
7 |
Correct |
11 ms |
23896 KB |
Output is correct |
8 |
Correct |
9 ms |
24300 KB |
Output is correct |
9 |
Correct |
10 ms |
24220 KB |
Output is correct |
10 |
Correct |
10 ms |
24156 KB |
Output is correct |
11 |
Correct |
8 ms |
24220 KB |
Output is correct |
12 |
Correct |
9 ms |
24208 KB |
Output is correct |
13 |
Correct |
8 ms |
23900 KB |
Output is correct |
14 |
Correct |
8 ms |
23900 KB |
Output is correct |
15 |
Correct |
1031 ms |
130444 KB |
Output is correct |
16 |
Correct |
903 ms |
133200 KB |
Output is correct |
17 |
Correct |
942 ms |
109216 KB |
Output is correct |
18 |
Correct |
896 ms |
111008 KB |
Output is correct |
19 |
Correct |
821 ms |
110756 KB |
Output is correct |
20 |
Correct |
891 ms |
108204 KB |
Output is correct |
21 |
Correct |
792 ms |
108048 KB |
Output is correct |
22 |
Correct |
826 ms |
106264 KB |
Output is correct |
23 |
Correct |
801 ms |
104600 KB |
Output is correct |
24 |
Correct |
786 ms |
103580 KB |
Output is correct |
25 |
Correct |
718 ms |
100732 KB |
Output is correct |
26 |
Correct |
740 ms |
100060 KB |
Output is correct |
27 |
Correct |
635 ms |
97756 KB |
Output is correct |
28 |
Correct |
657 ms |
97460 KB |
Output is correct |
29 |
Correct |
271 ms |
80840 KB |
Output is correct |
30 |
Correct |
274 ms |
80832 KB |
Output is correct |
31 |
Correct |
921 ms |
111004 KB |
Output is correct |
32 |
Correct |
956 ms |
108316 KB |
Output is correct |
33 |
Correct |
964 ms |
111008 KB |
Output is correct |
34 |
Correct |
1000 ms |
110992 KB |
Output is correct |
35 |
Correct |
8 ms |
23900 KB |
Output is correct |
36 |
Correct |
7 ms |
23896 KB |
Output is correct |
37 |
Correct |
1072 ms |
111632 KB |
Output is correct |
38 |
Correct |
1076 ms |
111260 KB |
Output is correct |
39 |
Correct |
984 ms |
111020 KB |
Output is correct |
40 |
Correct |
1024 ms |
111040 KB |
Output is correct |
41 |
Correct |
10 ms |
23896 KB |
Output is correct |
42 |
Correct |
1122 ms |
120856 KB |
Output is correct |
43 |
Correct |
1040 ms |
139988 KB |
Output is correct |
44 |
Correct |
1055 ms |
127140 KB |
Output is correct |
45 |
Correct |
1028 ms |
134044 KB |
Output is correct |
46 |
Correct |
998 ms |
125556 KB |
Output is correct |
47 |
Correct |
984 ms |
118592 KB |
Output is correct |
48 |
Correct |
936 ms |
130532 KB |
Output is correct |
49 |
Correct |
920 ms |
117152 KB |
Output is correct |
50 |
Correct |
1006 ms |
120972 KB |
Output is correct |
51 |
Correct |
365 ms |
92996 KB |
Output is correct |
52 |
Correct |
329 ms |
85476 KB |
Output is correct |
53 |
Correct |
210 ms |
71188 KB |
Output is correct |
54 |
Correct |
186 ms |
73736 KB |
Output is correct |
55 |
Correct |
1091 ms |
129460 KB |
Output is correct |
56 |
Correct |
1125 ms |
113376 KB |
Output is correct |
57 |
Correct |
418 ms |
99468 KB |
Output is correct |