Pagini recente » Cod sursa (job #1818304) | Cod sursa (job #2247930) | Cod sursa (job #2736217) | Cod sursa (job #2734729) | Cod sursa (job #2607705)
#include <fstream>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;
ifstream fin("pitici.in");
ofstream fout("pitici.out");
const int NMAX = 1020;
int n, m, k, x, y, c;
typedef pair <int, int> p;
vector <p> g[NMAX];
priority_queue <p, vector <p>, greater <p> > q;
vector <int> pit;
void Dijkstra()
{
q.push({ 0, 1 });
while (!q.empty())
{
p a = q.top();
q.pop();
if (a.second == n)
{
fout << a.first << " ";
k--;
if (k == 0)
return;
}
for (size_t i = 0; i < g[a.second].size(); ++i)
{
y = g[a.second][i].first, c = g[a.second][i].second + a.first;
q.push({ c, y });
}
}
}
int main()
{
fin >> n >> m >> k;
for (int i = 1; i <= m; ++i)
{
fin >> x >> y >> c;
g[x].push_back({ y, c });
}
Dijkstra();
fout.close();
return 0;
}