public static int UltimateSink(bool [,] m, int V)
for(int vertex = 1; vertex < V; vertex++)
if(!m[vertex, candidate])
for(int vertex = 0; vertex < V; vertex++)
if(m[candidate, vertex] || !m[vertex,candidate])
public static void Main()
bool [,] m1 = new bool[4,4]
{true, true, true, true},
{true, true, true, true},
{true, true, true, true},
{false, false, false, true}
bool [,] m2 = new bool[4,4]
{true, false, true, false},
{true, true, true, true},
{true, true, true, true},
{false, false, false, true}
bool [,] m3 = new bool[4,4]
{true, true, true, false},
{false, true, false, false},
{true, true, true, true},
{true, true, false, true}
Test("1x1 with 0s", new bool[1,1] {{false}}, 1);
Test("1x1 with 1s", new bool[1,1] {{true}}, 1);
Test("2x2 with 0s", new bool[2,2] {{false, false}, {false, false}}, 2);
Test("2x2 with 1s", new bool[2,2] {{true, true}, {true, true}}, 2);
private static void Test(string test, bool [,] m, int V)
int sink = UltimateSink(m, V);
Console.WriteLine("Test {0}: vertex {1} is an ultimate sink", test, sink);
Console.WriteLine("Test {0}: no ultimate sink", test);