Cod sursa(job #3145048)

Utilizator NanuGrancea Alexandru Nanu Data 12 august 2023 13:20:42
Problema Pitici Scor 20
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.93 kb
#include <fstream>
#include <queue>
#include <vector>
#include <set>

using namespace std;

ifstream fin("pitici.in");
ofstream fout("pitici.out");

const int NMAX = 1020;

int n, m, k;
int level[NMAX + 5], viz[NMAX + 5];
multiset <int> M[NMAX + 5];
vector <pair<int, int>> G[NMAX + 5];
priority_queue <pair<int, int>> PQ;

static inline void bfs() {
  PQ.push({1, 1});
  M[1].insert(1);
  while(!PQ.empty()) {
    int nod = PQ.top().second;
    int d = PQ.top().first;
    PQ.pop();

    for(auto e : G[nod]) {
        PQ.push({d + e.second, e.first});
        M[e.first].insert(d + e.second);
      }
  }
}

int main() {
  fin.tie(0), fout.tie(0);

  fin >> n >> m >> k;
  for(int i = 1, x, y, z; i <= m; i++) {
    fin >> x >> y >> z;
    G[x].push_back({y, z});
  }

  bfs();

  int nr = 0;
  for(auto e : M[n]) {
    nr++;
    fout << e - 1 << " ";
    if(nr == k)
      break;
  }

  return 0;
}