C# graph algorithms