Pagini recente » Cod sursa (job #2688609) | Cod sursa (job #1676696) | Cod sursa (job #557462) | Cod sursa (job #2539502) | Cod sursa (job #1801587)
#include <bits/stdc++.h>
using namespace std;
const int Nmax = 1023;
typedef pair<int,int> Pair;
int n, m, x, y, cost, cnt[Nmax], k, i;
bool used[Nmax];
vector<int> path[Nmax];
vector<Pair> v[Nmax];
void dfs(int node)
{
priority_queue< Pair, vector<Pair>, greater<Pair> > heap;
int act, cost;
used[node] = 1;
for(auto it : v[node])
{
act = it.first;
cost = it.second;
if(!used[act]) dfs(act);
if(!path[act].empty())
heap.push({ path[act][0] + cost, act });
cnt[act] = 0;
}
while(!heap.empty() && path[node].size() < k)
{
cost = heap.top().first;
act = heap.top().second;
heap.pop();
path[node].push_back(cost);
if(++cnt[act] < path[act].size())
heap.push({ cost + path[act][cnt[act]] - path[act][cnt[act]-1], act });
}
}
int main()
{
ifstream zin("pitici.in");
ofstream zout("pitici.out");
zin >> n >> m >> k;
while(m--)
{
zin >> x >> y >> cost;
v[x].push_back({ y, cost });
}
path[n].push_back(0);
dfs(1);
for(i=0; i<k; ++i) zout << path[1][i] << " ";
return 0;
}