Pagini recente » Cod sursa (job #2815542) | Cod sursa (job #2372468) | Cod sursa (job #50875) | Cod sursa (job #3152233) | Cod sursa (job #3198313)
#include <bits/stdc++.h>
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
using namespace std;
ifstream fin("pitici.in");
ofstream fout("pitici.out");
struct cv {
short node;
int cost;
bool operator<(const cv& foreign) const {
return this->cost > foreign.cost;
}
};
short N,K;
int M;
vector<pair<short,short>> G[1020];
array<short,1020> viz;
int main() {
ios_base::sync_with_stdio(false);
fin.tie(NULL);
fin >> N >> M >> K;
for (int i = 1; i <= M; i++) {
short nodeA, nodeB, cost;
fin >> nodeA >> nodeB >> cost;
G[nodeB].push_back({nodeA,cost});
}
priority_queue<cv> pq,ans;
for (const pair<short,short>& edge : G[N]) {
pq.push({edge.first, edge.second});
}
G[N].clear();
while (!pq.empty()) {
if (pq.top().node == 1) {
ans.push(pq.top());
if (ans.size() == K) {
break;
}
} else {
for (const pair<short,short>& edge : G[pq.top().node]) {
if (viz[edge.first] <= K) {
pq.push({edge.first, edge.second + pq.top().cost});
viz[edge.first]++;
}
}
}
pq.pop();
}
while (K--) {
fout << ans.top().cost << ' ';
ans.pop();
}
return 0;
}