Cod sursa(job #3206146)

Utilizator susanEmily Susan susan Data 21 februarie 2024 18:47:55
Problema Pitici Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.69 kb
#include <fstream>
#include <queue>

using namespace std;

int main() {
    ifstream f("pitici.in");
    ofstream g("pitici.out");

    int n, m, k, a, b, cost;
    f >> n >> m >> k;

    vector<vector<pair<int, int>>> G(n + 1);

    while (m--) {
        f >> a >> b >> cost;
        G[b].emplace_back(a, cost);
    }

    queue<pair<int, int>> Q;
    for (auto &[nod, tot]: G[n])
        Q.emplace(nod, tot);


    while (!Q.empty()) {
        auto [nod, tot] = Q.front();
        Q.pop();

        if (nod == 1) {
            g << tot << ' ';
            if (--k == 0)
                break;
        } else
            for (auto &[nod2, pret]: G[nod])
                Q.emplace(nod2, tot + pret);
    }
}