For coursework needed software implementation of this algorithm. Tell me, please, what is wrong? And then I can not understand, really need a view from the side. Here's what I got:

## Заголовок ## int n, s, m, k=0, mod_e=0; // k - счетчик массивов ребер int[] a = new int[200]; // массив начал ребер int[] b = new int[200]; // массив концов ребер int[] w = new int[200]; // массив весов ребер int[] d = new int[200]; // массив расстояний Console.WriteLine("Введите количество вершин:"); n = int.Parse(Console.ReadLine()); // Количество вершин Console.WriteLine("Введите номер стартовой вершины:"); s = int.Parse(Console.ReadLine()); // Стартовая вершина for (int i = 1; i <= n; i++) // Задание массивов ребер { Console.WriteLine("Введите количество ребер, исходящих из вершины " +i); m = int.Parse(Console.ReadLine()); for (int j = 1; j <= m; j++) { a[k] = i; Console.WriteLine("Введите номер конечной вершины для "+ j + "-го ребра, исходящего из "+ i+ ":"); b[k] = int.Parse(Console.ReadLine()); Console.WriteLine("Введите вес "+ j+ "-го ребра, исходящего из "+ i+ ":"); w[k] = int.Parse(Console.ReadLine()); k++; } mod_e++; // Кол-во ребер (во всем графе) } for (int i = 1; i <= n; i++) d[i] = 999999; d[s] = 0; for (int i = 1; i < n; i++) { if (i == s) i++; else { for (int j = 1; j <= mod_e; j++) { if (d[b[j]] > (d[a[j]] + w[j])) d[b[j]] = d[a[j]] + w[j]; j++; } i++; } } for (int i = 1; i <= n; i++) { Console.WriteLine("Кратчайший путь до вершины " + i + " = " + d[i]); } Console.WriteLine(d); Console.ReadLine(); 
  • Thank you very much, everything worked)) - ratava

1 answer 1

At least the number of edges in the entire graph (mod_e) is considered incorrect. In theory, it should be k (this is the same thing). Plus, for some reason, indexing everywhere in arrays starts from 1, and not from 0 (although there seems to be no errors due to this).