Hi, I've been trying to solve this problem. It runs fine in visual studio, but I keep getting an NZEC on the judge.
Is there any way to find out from the judge where the error occurred?
Any help would be appreciated.
using System;
using System.Collections;
class SHPATH
{
#region "Struct Node"
// Item to be used in priority queue
public struct Node
{
public int ID, Cost;
public Node(int NewID, int NewCost)
{
ID = NewID;
Cost = NewCost;
}
public static bool operator <(Node a, Node b)
{
if(b.Cost > a.Cost) return true;
else return false;
}
public static bool operator >(Node a, Node b)
{
if(a.Cost > b.Cost) return true;
else return false;
}
}
#endregion
#region "Main Program"
public static void Main()
{
string[] cities = new string[10001];
int[,] edges = new int[10001, 10001]; //[from, to]
int[] bestCost = new int[10001];
ArrayList q = new ArrayList();
int nTests = int.Parse(Console.ReadLine());
while (nTests-- > 0)
{
int nCities = int.Parse(Console.ReadLine());
for(int i = 1; i <= nCities; i++)
{
for (int j = 1; j <= nCities; j++)
edges[i, j] = 200000; // maximum value for a path, prevents travel
cities[i] = Console.ReadLine();
int nRoads = int.Parse(Console.ReadLine());
for(int j = 1; j <= nRoads; j++)
{
string[] s = Console.ReadLine().Split(' ');
int dest = int.Parse(s[0]);
edges[i,dest] = int.Parse(s[1]);
}
}
int nChecks = int.Parse(Console.ReadLine());
for(int i = 1; i <= nChecks; i++)
{
string [] s = Console.ReadLine().Split(' ');
string c1 = s[0];
string c2 = s[1];
int idxC1 = 0;
int idxC2 = 0;
for (int j = 1; j <= nCities; j++)
{
bestCost[j] = 200000; // maximum cost for a path
if (cities[j] == c2)
idxC2 = j;
else if (cities[j] == c1)
idxC1 = j;
}
q.Add(new Node(idxC1, 0));
while (q.Count > 0)
{
Node p = (Node)q[0];
q.RemoveAt(0);
if (p.Cost < bestCost[p.ID])
{
bestCost[p.ID] = p.Cost;
for (int j = 1; j <= nCities; j++)
{
if (p.Cost + edges[p.ID, j] < bestCost[j])
{
Node l = new Node(j, p.Cost + edges[p.ID, j]);
bool added = false;
for (int k = 0; k < q.Count; k++)
{
if (l < (Node)q[k])
{
added = true;
q.Insert(k, l);
break;
}
}
if (!added) q.Add(l);
}
}
}
}
Console.WriteLine(bestCost[idxC2]);
}
if(nTests > 0) Console.ReadLine();
}
}
#endregion
}