Pagini recente » Cod sursa (job #1783004) | Cod sursa (job #315365) | Cod sursa (job #3149537) | Cod sursa (job #2508893) | Cod sursa (job #3145052)
#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);
while(M[e.first].size() > k) {
M[e.first].erase(--M[e.first].end());
}
}
}
}
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();
for(auto e : M[n])
fout << e - 1 << " ";
return 0;
}