Pagini recente » Cod sursa (job #2089577) | Cod sursa (job #2612683) | Cod sursa (job #42815) | Cod sursa (job #2908514) | Cod sursa (job #1701584)
#include <fstream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <queue>
using namespace std;
ifstream fin("pitici.in");
ofstream fout("pitici.out");
const int dim = 1105;
typedef pair<int, int> pii;
int n, m, k;
vector<pii> g[dim];
bool vis[dim];
vector<int> path[dim];
void dfs(int node) {
vis[node] = true;
if (g[node].empty()) {
if (node == n)
path[node].push_back(0);
return;
}
vector<pii> sons;
vector<int> extra;
priority_queue<pii> heap;
for (pii adj : g[node]) {
if (!vis[adj.first])
dfs(adj.first);
sons.push_back(pii(adj.first, 0));
extra.push_back(adj.second);
if (path[adj.first].size() != 0)
heap.push(pii(-path[adj.first][0] - extra.back(), sons.size() - 1));
}
while (!heap.empty() && (int)path[node].size() < k) {
pii aux = heap.top();
heap.pop();
int son = aux.second;
path[node].push_back(-aux.first);
sons[son].second++;
if (sons[son].second < (int)path[sons[son].first].size())
heap.push(pii(-path[sons[son].first][sons[son].second] - extra[son], son));
}
}
int main() {
fin >> n >> m >> k;
for (int i = 1; i <= m; ++i) {
int a, b, c;
fin >> a >> b >> c;
g[a].push_back(pii(b, c));
}
dfs(1);
for (int i = 0; i < k; ++i)
fout << path[1][i] << ' ';
fout << '\n';
return 0;
}
//Trust me, I'm the Doctor!