Pagini recente » Cod sursa (job #83038) | Cod sursa (job #659374) | Cod sursa (job #1772611) | Cod sursa (job #851708) | Cod sursa (job #3266175)
#include <fstream>
#include <queue>
#include <vector>
using namespace std;
int cost[100001];
queue <int> Nod;
vector <pair<int,int>> V[50001];
int main()
{
ifstream fin("dijkstra.in");
ofstream fout("dijkstra.out");
int n, m, a, b, c;
fin >> n >> m;
for (int i = 1; i <= m; i++)
{
fin >> a >> b >> c;
V[a].push_back(make_pair(b, c));
}
for (int i = 2; i <= n; i++)
cost[i] = 1000000005;
cost[1] = 0;
Nod.push(1);
while (!Nod.empty())
{
int currentNode = Nod.front();
Nod.pop();
for (auto x : V[currentNode])
{
if (cost[x.first] > cost[currentNode] + x.second)
{
cost[x.first] = cost[currentNode] + x.second;
Nod.push(x.first);
}
}
}
for (int i = 2; i <= n; i++)
fout << cost[i]*(1-cost[i]/1000000005) << " ";
return 0;
}