Submission #1131763

#TimeUsernameProblemLanguageResultExecution timeMemory
1131763VMaksimoski008Treasure Hunt (CCO24_day1problem1)C++20
25 / 25
2058 ms122336 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...