Pagini recente » Cod sursa (job #974605) | Cod sursa (job #157408) | Cod sursa (job #191039) | Cod sursa (job #240758) | Cod sursa (job #3145048)
#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;
}