Graph algorithms in C#