Cod sursa(job #2206695)

Utilizator EricEric Vilcu Eric Data 23 mai 2018 14:44:15
Problema Algoritmul lui Dijkstra Scor 90
Compilator cpp Status done
Runda Arhiva educationala Marime 0.6 kb
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("dijkstra.in");
ofstream g("dijkstra.out");
struct {int a,b,c;} m[250009];
int n,o,d[50009];
bool k=1;
int main()
{
    f>>o;
    for(int h=0;h<=o;++h)d[h]=20000*50000+7;
    d[1]=0;
    f>>n;
    for(int h=0;h<n;++h)f>>m[h].a>>m[h].b>>m[h].c;
    while(k)
    {
        k=0;
        for(int i=0;i<n;++i)if(d[m[i].b]>d[m[i].a]+m[i].c)
        {
            d[m[i].b]=d[m[i].a]+m[i].c;
            k=1;
        }
    }
    for(int h=2;h<=o;++h)if(d[h]!=d[0])g<<d[h]<<' ';
                         else g<<0<<' ';
}