[ create a new paste ] login | about

Link: http://codepad.org/VmSAqTpv    [ raw code | output | fork ]

C++, pasted on Jun 24:
#include <iostream>

int main() {
    // Adjacency Matrix of your graph
    const int n = 5;
    bool d[n][n] = {
       { 0, 1, 1, 0, 0 },
       { 0, 0, 1, 0, 0 }, 
       { 0, 0, 0, 1, 0 },
       { 0, 0, 0, 0, 1 },
       { 0, 0, 0, 0, 0 },
    };

    // Modified Warshall Algorithm
    bool out[n][n] = {};
    for (int k = 0; k < n; k++)
        for (int i = 0; i < n; i++)
            if (d[i][k])
                for (int j = 0; j < n; j++)
                    if (d[k][j] && !d[i][j])
                        std::cout << i + 1 << " " << j + 1 << std::endl;
}


Output:
1
2
3
1 4
2 4
3 5


Create a new paste based on this one


Comments: