function isIsomorphic(n, g1, g2) {
const root1 = getCentersOfTree(n, g1);
const tree1 = createRootedTree(g1, root1[0]);
const serializedTree1 = serializeTree(tree1);
const root2 = getCentersOfTree(n, g2);
for (const root of root2) {
const tree = createRootedTree(g2, root);
const serializedTree2 = serializeTree(tree);
if (serializedTree1 === serializedTree2) {
return true;
}
}
return false;
}