Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bool checkIsomorphism(Graph firstGraph, Graph secondGraph)
- {
- int nodesCount = firstGraph.nodesCount;
- int secondGraphMatrix[nodesCount][nodesCount]{-1};
- int values[nodesCount];
- for (int i = 0; i < nodesCount; i++)
- {
- values[i] = i;
- int ssize = secondGraph.nodes[i].size();
- for (int s = 0; s < ssize; s++)
- {
- secondGraphMatrix[i][secondGraph.nodes[i][s]] = s;
- }
- }
- do {
- for (int i = 0; i < nodesCount; i++)
- {
- int fsize = firstGraph.nodes[i].size();
- if (secondGraph.nodes[values[i]].size() != firstGraph.nodes[i].size())
- return false;
- for (int j = 0; j < fsize; j++)
- {
- if (values[firstGraph.nodes[i][j]] != secondGraph.nodes[values[i]][values[firstGraph.nodes[i][j]]])
- return false;
- }
- }
- } while (std::next_permutation(values, values + nodesCount));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement