114
dist[u] != int.MaxValue && dist[u] + graph[u, v] < dist[v])
1
// A C# program for Dijkstra's single
2
// source shortest path algorithm.
3
// The program is for adjacency matrix
4
// representation of the graph
5
using System;
6
7
public class Program {
8
// A utility function to find the
9
// vertex with minimum distance
10
// value, from the set of vertices
11
// not yet included in shortest
12
// path tree
13
static int V = 9;
14
int minDistance(int[] dist,
15
bool[] sptSet)
16
{
17
// Initialize min value
18
int min = int.MaxValue, min_index = -1;
19
20
for (int v = 0; v < V; v++)
21
if (sptSet[v] == false && dist[v] <= min) {
22
min = dist[v];
23
min_index = v;
24
}
Cached Result