#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
signed main() {
int n, m; cin >> n >> m;
vector<int> a(n+1);
for(int i=1; i<=n; i++) cin >> a[i];
vector<pll> G[n+1];
for(int i=1; i<=m; i++) {
int a, b, w; cin >> a >> b >> w;
G[a].push_back({ b, w });
G[b].push_back({ a, w });
}
vector<ll> dist(n+1, -1);
priority_queue<pll> pq;
for(int i=1; i<=n; i++) pq.push({ a[i], i });
while(!pq.empty()) {
auto [d, u] = pq.top(); pq.pop();
if(dist[u] != -1) continue;
dist[u] = d;
for(auto [v, w] : G[u])
pq.push({ d - w, v });
}
for(int i=1; i<=n; i++) cout << dist[i] << '\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |