Cod sursa(job #2978705)
Utilizator | Data | 14 februarie 2023 08:10:31 | |
---|---|---|---|
Problema | Algoritmul Bellman-Ford | Scor | 0 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.48 kb |
void ford(int nod)
{
int x, ps = 1, pi = 1;
c[ps] = nod;
while (ps <= pi) {
viz[c[ps]] = 0;
x = start[c[ps]];
while (x) {
if (cost[c[ps]] + a[2][x] < cost[a[0][x]]) {
cost[a[0][x]] = cost[c[ps]] + a[2][x];
if(viz[a[0][x]] == 0) {
viz[a[0][x]] = 1;
c[++pi] = a[0][x];
}
}
x = a[1][x];
}
ps++;
}
}