Pagini recente » Cod sursa (job #1224942) | Cod sursa (job #2922133) | Cod sursa (job #1592578) | Cod sursa (job #3143136) | Cod sursa (job #1563264)
#include <cstring>
#include <fstream>
#include <queue>
#include <tuple>
#include <vector>
using namespace std;
typedef tuple<int, int, int> Node;
const int N_MAX = 1019;
const int K_MAX = 1019;
ifstream fin("pitici.in");
ofstream fout("pitici.out");
int N, M, K;
vector<int> G[N_MAX + 5];
int cost[N_MAX + 5][N_MAX + 5];
bool use[N_MAX + 5];
vector<int> order;
int best[N_MAX + 5][K_MAX + 5];
void Dfs(int node) {
use[node] = true;
for (int son : G[node])
if (!use[son])
Dfs(son);
order.push_back(node);
}
int main() {
fin >> N >> M >> K;
while (M--) {
int x, y, c;
fin >> x >> y >> c;
G[x].push_back(y);
cost[x][y] = c;
}
Dfs(1);
memset(best, 0x3f, sizeof best);
best[N][0] = 0;
for (int node : order) {
if (G[node].empty())
continue;
priority_queue<Node, vector<Node>, greater<Node>> q;
for (int to : G[node])
q.emplace(best[to][0] + cost[node][to], to, 0);
for (int i = 0; i < K; ++i) {
int dist, to, indx;
tie(dist, to, indx) = q.top();
q.pop();
q.emplace(best[to][indx + 1] + cost[node][to], to, indx + 1);
best[node][i] = dist;
}
}
for (int i = 0; i < K; ++i)
fout << best[1][i] << " ";
fout << "\n";
return 0;
}