{"ScriptPreparationCode":null,"TestCases":[{"Name":"test111","Code":"function traverse(tree,root){\r\n if (!root) return \u0022\u0022\r\n let val = \u0022(\u0022 \u002B root\r\n if (!tree[root]) {\r\n val \u002B= \u0022)\u0022\r\n } else \r\n {\r\n let pair = tree[root]\r\n let left = pair[0]\r\n let right = pair[1]\r\n val \u002B= traverse(tree,left)\r\n val \u002B= traverse(tree,right)\r\n val \u002B= \u0022)\u0022\r\n }\r\n return val\r\n \r\n}\r\nfunction parseTree(edges){\r\n const tree = {}\r\n\r\n for (let pair of edges){\r\n if (!tree[pair[1]]) tree[pair[1]] = []\r\n tree[pair[1]].push(pair[3])\r\n }\r\n return tree\r\n}\r\n\r\nfunction isValidTree(tree, numOfEdges) {\r\n if (!tree || !Object.keys(tree)) return \u0022E5\u0022\r\n const root = Object.keys(tree).sort()[0]\r\n const queue = [root]\r\n const visited = new Set(root)\r\n while (queue.length) {\r\n const nodes = tree[queue.pop()]\r\n if (!nodes) continue\r\n if (visited.has(nodes[0]) || visited.has(nodes[1])) return \u0022E3\u0022\r\n if (nodes.length \u003E 2) return \u0022E1\u0022\r\n if (nodes[0] == nodes[1]) return \u0022E2\u0022\r\n queue.push(...nodes)\r\n visited.add(nodes[0])\r\n nodes[1] \u0026\u0026 visited.add(nodes[1])\r\n }\r\n if (numOfEdges != visited.size - 1) return \u0022E4\u0022\r\n return \u0022E0\u0022\r\n}\r\n\r\nfunction binarySym(treeString=\u0022(B,D) (D,E) (A,B) (C,F) (E,G) (A,C)\u0022) {\r\n console.log(\u0022================\u0022)\r\n const edges = treeString.split(\u0022 \u0022)\r\n let tree = parseTree(edges)\r\n const isValid = isValidTree(tree, edges.length)\r\n if (isValid != \u0022E0\u0022) return isValid\r\n const rootNode = Object.keys(tree).sort()[0]\r\n let rv = traverse(tree,rootNode)\r\n return rv\r\n \r\n}\r\n\r\nbinarySym()","IsDeferred":false},{"Name":"test222","Code":"function traverse(tree,root){\r\n if (!root) return \u0022\u0022\r\n let val = \u0022(\u0022 \u002B root\r\n if (!tree[root]) {\r\n val \u002B= \u0022)\u0022\r\n } else \r\n {\r\n let pair = tree[root]\r\n let left = pair[0]\r\n let right = pair[1]\r\n val \u002B= traverse(tree,left)\r\n val \u002B= traverse(tree,right)\r\n val \u002B= \u0022)\u0022\r\n }\r\n return val\r\n \r\n}\r\nfunction parseTree(edges){\r\n const tree = {}\r\n\r\n for (let pair of edges){\r\n if (!tree[pair[1]]) tree[pair[1]] = []\r\n tree[pair[1]].push(pair[3])\r\n }\r\n return tree\r\n}\r\n\r\nfunction isValidTree(tree, numOfEdges) {\r\n if (!tree || !Object.keys(tree)) return \u0022E5\u0022\r\n const root = Object.keys(tree).sort()[0]\r\n const queue = [root]\r\n const visited = new Set(root)\r\n while (queue.length) {\r\n const nodes = tree[queue.pop()]\r\n if (!nodes) continue\r\n if (visited.has(nodes[0]) || visited.has(nodes[1])) return \u0022E3\u0022\r\n if (nodes.length \u003E 2) return \u0022E1\u0022\r\n if (nodes[0] == nodes[1]) return \u0022E2\u0022\r\n queue.push(...nodes)\r\n visited.add(nodes[0])\r\n nodes[1] \u0026\u0026 visited.add(nodes[1])\r\n }\r\n if (numOfEdges != visited.size - 1) return \u0022E4\u0022\r\n return \u0022E0\u0022\r\n}\r\n\r\nfunction binarySym(treeString=\u0022(B,D) (D,E) (A,B) (C,F) (E,G) (A,C)\u0022) {\r\n console.log(\u0022================\u0022)\r\n const edges = treeString.split(\u0022 \u0022)\r\n let tree = parseTree(edges)\r\n const isValid = isValidTree(tree, edges.length)\r\n if (isValid != \u0022E0\u0022) return isValid\r\n const rootNode = Object.keys(tree).sort()[0]\r\n let rv = traverse(tree,rootNode)\r\n return rv\r\n \r\n}\r\n\r\nbinarySym()","IsDeferred":false}]}