C# graphs algorithms