using System.Collections.Generic;
public int Source { get; set; }
public int Dest { get; set; }
public int Weight { get; set; }
const int NUM_NODES = 11;
public static void Main()
var edges = new List<Edge>();
{{ 0, 4, 0, 0, 0, 0, 0, 4, 5, 0, 0 },
{ 0, 0, 6, 0, 0, 0, 0, 0, 0, 4, 0 },
{ 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 4, 0, 0, 4, 0 },
{ 0, 0, 3, 0, 0, 0, 2, 0, 0, 1, 0 },
{ 0, 0, 0, 7, 0, 1, 0, 0, 0, 0, 3 },
{ 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0 }};
for (var i = 0; i < NUM_NODES; i++) {
for (var j = 0; j < NUM_NODES; j++) {
if (graph[i,j] == 0) continue;
edge.Weight = graph[i,j];
public void PrintArray(int[] array) {
for (var x = 0; x < array.GetLength(0); x++) {
Console.Write(array[x].ToString().PadRight(3, ' '));
public void PrintArray(int[,] array) {
for (var x = 0; x < array.GetLength(0); x++) {
for (var y = 0; y < array.GetLength(1); y++) {
Console.Write(array[x, y].ToString().PadRight(3, ' '));
public void BellmanFord(int[,]graph, int start) {
var distance = new int[NUM_NODES];
var visited=new bool[NUM_NODES];
for (var i = 0; i < NUM_NODES; i++) {
distance[i] = int.MaxValue;
for(int i=0; i<NUM_NODES; i++)
if((graph[start,i]+distance[start]<distance[i])&&graph[start,i]!=0)
distance[i] = graph[start,i]+distance[start];
visited[start] = true; start = -1;
int mindistance = int.MaxValue;
for(int i=0; i<NUM_NODES; i++)
if(!visited[i] && (distance[i] < mindistance)){
start = i; mindistance = distance[i];