Answer the question
In order to leave comments, you need to log in
How to check the adjacency matrix of an undirected graph for correctness?
I understand that the adjacency matrix of an undirected graph will be correct if it is symmetrical with respect to the diagonal coming from the point (0; 0), but it doesn’t work out.
bool is_adjacency_matrix(const vector<string>& matrix) {
for (auto i = 0; i < matrix.size(); i++) {
for (auto j = i; j < matrix[i].size(); j++) {
if (matrix[i][j] != matrix[j][i])
return false;
}
}
return true;
}
Answer the question
In order to leave comments, you need to log in
raster , how to understand your
write fails, if you immediately give the code - which, by the way, is able to solve the problem. Well, unless:
bool is_adjacency_matrix_correct(const vector<string>& matrix) {
size=matrix[0].size();
for (auto i = 0; i < size-1; i++) {
for (auto j = i+1; j < size; j++) {
if (matrix[i][j] != matrix[j][i])
return false;
}
}
return true;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question