Back to the Problem
Check g[i][j] = g[j][i] for all pairs (the upper triangle suffices).
Complexity: O(N2)