938D - Buy a Ticket - CodeForces Solution


data structures graphs shortest paths *2000

Please click on ads to support us..

C++ Code:

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
typedef pair<ll, ll> p;
priority_queue<p> q;
const int N = 2e5 + 1;
ll i, v, u, w, n, m, a[N], mn[N], V[N];
vector<p> G[N];

int main() {
    cin >> n >> m;
    for (i = 0; i < m; ++i)
        cin >> v >> u >> w, G[v].push_back({u, -w * 2}), G[u].push_back({v, -w * 2});
    for (i = 1; i <= n; ++i) cin >> w, q.push({-w, i});
    while (!q.empty()) {
        auto [c, x] = q.top();
        q.pop();
        if (V[x]) continue;
        mn[x] = c, V[x] = 1;
        for (auto &[y, d]: G[x]) q.push({c + d, y});
    }
    for (i = 1; i <= n; ++i) cout << -mn[i] << ' ';
    cout << '\n';
}

/* Sat Feb 18 2023 18:46:58 GMT+0300 (Moscow Standard Time) */


Comments

Submit
0 Comments
More Questions

747A - Display Size
285A - Slightly Decreasing Permutations
515C - Drazil and Factorial
1151E - Number of Components
1151F - Sonya and Informatics
556A - Case of the Zeros and Ones
867A - Between the Offices
1569A - Balanced Substring
260A - Adding Digits
1698C - 3SUM Closure
1029B - Creating the Contest
1421A - XORwice
1029A - Many Equal Substrings
1675D - Vertical Paths
1271C - Shawarma Tent
805A - Fake NP
1163A - Eating Soup
787A - The Monster
807A - Is it rated
1096A - Find Divisible
1430C - Numbers on Whiteboard
1697B - Promo
208D - Prizes Prizes more Prizes
659A - Round House
1492C - Maximum width
171B - Star
1512B - Almost Rectangle
831B - Keyboard Layouts
814A - An abandoned sentiment from past
268C - Beautiful Sets of Points