Pagini recente » Cod sursa (job #228249) | Cod sursa (job #2342854) | Cod sursa (job #574530) | Cod sursa (job #230735) | Cod sursa (job #3197780)
#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];
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]) {
pq.push({edge.first, edge.second + pq.top().cost});
}
}
pq.pop();
}
while (K--) {
fout << ans.top().cost << ' ';
ans.pop();
}
return 0;
}