|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "code", |
| 5 | + "execution_count": 1, |
| 6 | + "id": "imports", |
| 7 | + "metadata": {}, |
| 8 | + "outputs": [], |
| 9 | + "source": [ |
| 10 | + "from solution import Solution\n", |
| 11 | + "\n", |
| 12 | + "from leetcode_py import GraphNode" |
| 13 | + ] |
| 14 | + }, |
| 15 | + { |
| 16 | + "cell_type": "code", |
| 17 | + "execution_count": 2, |
| 18 | + "id": "setup", |
| 19 | + "metadata": {}, |
| 20 | + "outputs": [ |
| 21 | + { |
| 22 | + "data": { |
| 23 | + "text/html": [ |
| 24 | + "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n", |
| 25 | + "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n", |
| 26 | + " \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n", |
| 27 | + "<!-- Generated by graphviz version 13.1.2 (20250808.2320)\n", |
| 28 | + " -->\n", |
| 29 | + "<!-- Pages: 1 -->\n", |
| 30 | + "<svg width=\"135pt\" height=\"138pt\"\n", |
| 31 | + " viewBox=\"0.00 0.00 135.00 138.00\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n", |
| 32 | + "<g id=\"graph0\" class=\"graph\" transform=\"scale(1 1) rotate(0) translate(4 134.25)\">\n", |
| 33 | + "<polygon fill=\"white\" stroke=\"none\" points=\"-4,4 -4,-134.25 131.36,-134.25 131.36,4 -4,4\"/>\n", |
| 34 | + "<!-- 1 -->\n", |
| 35 | + "<g id=\"node1\" class=\"node\">\n", |
| 36 | + "<title>1</title>\n", |
| 37 | + "<ellipse fill=\"lightblue\" stroke=\"black\" cx=\"18\" cy=\"-53.59\" rx=\"18\" ry=\"18\"/>\n", |
| 38 | + "<text xml:space=\"preserve\" text-anchor=\"middle\" x=\"18\" y=\"-48.54\" font-family=\"Times,serif\" font-size=\"14.00\">1</text>\n", |
| 39 | + "</g>\n", |
| 40 | + "<!-- 2 -->\n", |
| 41 | + "<g id=\"node2\" class=\"node\">\n", |
| 42 | + "<title>2</title>\n", |
| 43 | + "<ellipse fill=\"lightblue\" stroke=\"black\" cx=\"109.36\" cy=\"-76.24\" rx=\"18\" ry=\"18\"/>\n", |
| 44 | + "<text xml:space=\"preserve\" text-anchor=\"middle\" x=\"109.36\" y=\"-71.19\" font-family=\"Times,serif\" font-size=\"14.00\">2</text>\n", |
| 45 | + "</g>\n", |
| 46 | + "<!-- 1--2 -->\n", |
| 47 | + "<g id=\"edge1\" class=\"edge\">\n", |
| 48 | + "<title>1--2</title>\n", |
| 49 | + "<path fill=\"none\" stroke=\"gray\" d=\"M35.61,-57.96C51.69,-61.94 75.33,-67.81 91.48,-71.81\"/>\n", |
| 50 | + "</g>\n", |
| 51 | + "<!-- 4 -->\n", |
| 52 | + "<g id=\"node3\" class=\"node\">\n", |
| 53 | + "<title>4</title>\n", |
| 54 | + "<ellipse fill=\"lightblue\" stroke=\"black\" cx=\"64.17\" cy=\"-18\" rx=\"18\" ry=\"18\"/>\n", |
| 55 | + "<text xml:space=\"preserve\" text-anchor=\"middle\" x=\"64.17\" y=\"-12.95\" font-family=\"Times,serif\" font-size=\"14.00\">4</text>\n", |
| 56 | + "</g>\n", |
| 57 | + "<!-- 1--4 -->\n", |
| 58 | + "<g id=\"edge2\" class=\"edge\">\n", |
| 59 | + "<title>1--4</title>\n", |
| 60 | + "<path fill=\"none\" stroke=\"gray\" d=\"M32.61,-42.33C38.1,-38.09 44.34,-33.28 49.81,-29.07\"/>\n", |
| 61 | + "</g>\n", |
| 62 | + "<!-- 3 -->\n", |
| 63 | + "<g id=\"node4\" class=\"node\">\n", |
| 64 | + "<title>3</title>\n", |
| 65 | + "<ellipse fill=\"lightblue\" stroke=\"black\" cx=\"63.48\" cy=\"-112.25\" rx=\"18\" ry=\"18\"/>\n", |
| 66 | + "<text xml:space=\"preserve\" text-anchor=\"middle\" x=\"63.48\" y=\"-107.2\" font-family=\"Times,serif\" font-size=\"14.00\">3</text>\n", |
| 67 | + "</g>\n", |
| 68 | + "<!-- 2--3 -->\n", |
| 69 | + "<g id=\"edge3\" class=\"edge\">\n", |
| 70 | + "<title>2--3</title>\n", |
| 71 | + "<path fill=\"none\" stroke=\"gray\" d=\"M94.84,-87.64C89.38,-91.92 83.18,-96.79 77.74,-101.05\"/>\n", |
| 72 | + "</g>\n", |
| 73 | + "<!-- 3--4 -->\n", |
| 74 | + "<g id=\"edge4\" class=\"edge\">\n", |
| 75 | + "<title>3--4</title>\n", |
| 76 | + "<path fill=\"none\" stroke=\"gray\" d=\"M63.61,-94.08C63.73,-77.49 63.91,-53.1 64.03,-36.44\"/>\n", |
| 77 | + "</g>\n", |
| 78 | + "</g>\n", |
| 79 | + "</svg>\n" |
| 80 | + ], |
| 81 | + "text/plain": [ |
| 82 | + "GraphNode({1: [2, 4], 2: [1, 3], 3: [2, 4], 4: [1, 3]})" |
| 83 | + ] |
| 84 | + }, |
| 85 | + "execution_count": 2, |
| 86 | + "metadata": {}, |
| 87 | + "output_type": "execute_result" |
| 88 | + } |
| 89 | + ], |
| 90 | + "source": [ |
| 91 | + "# Example test case\n", |
| 92 | + "adj_list = [[2, 4], [1, 3], [2, 4], [1, 3]]\n", |
| 93 | + "node = GraphNode.from_adjacency_list(adj_list)\n", |
| 94 | + "node" |
| 95 | + ] |
| 96 | + }, |
| 97 | + { |
| 98 | + "cell_type": "code", |
| 99 | + "execution_count": 3, |
| 100 | + "id": "execute", |
| 101 | + "metadata": {}, |
| 102 | + "outputs": [ |
| 103 | + { |
| 104 | + "data": { |
| 105 | + "text/html": [ |
| 106 | + "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n", |
| 107 | + "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n", |
| 108 | + " \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n", |
| 109 | + "<!-- Generated by graphviz version 13.1.2 (20250808.2320)\n", |
| 110 | + " -->\n", |
| 111 | + "<!-- Pages: 1 -->\n", |
| 112 | + "<svg width=\"135pt\" height=\"138pt\"\n", |
| 113 | + " viewBox=\"0.00 0.00 135.00 138.00\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n", |
| 114 | + "<g id=\"graph0\" class=\"graph\" transform=\"scale(1 1) rotate(0) translate(4 134.25)\">\n", |
| 115 | + "<polygon fill=\"white\" stroke=\"none\" points=\"-4,4 -4,-134.25 131.36,-134.25 131.36,4 -4,4\"/>\n", |
| 116 | + "<!-- 1 -->\n", |
| 117 | + "<g id=\"node1\" class=\"node\">\n", |
| 118 | + "<title>1</title>\n", |
| 119 | + "<ellipse fill=\"lightblue\" stroke=\"black\" cx=\"18\" cy=\"-53.59\" rx=\"18\" ry=\"18\"/>\n", |
| 120 | + "<text xml:space=\"preserve\" text-anchor=\"middle\" x=\"18\" y=\"-48.54\" font-family=\"Times,serif\" font-size=\"14.00\">1</text>\n", |
| 121 | + "</g>\n", |
| 122 | + "<!-- 2 -->\n", |
| 123 | + "<g id=\"node2\" class=\"node\">\n", |
| 124 | + "<title>2</title>\n", |
| 125 | + "<ellipse fill=\"lightblue\" stroke=\"black\" cx=\"109.36\" cy=\"-76.24\" rx=\"18\" ry=\"18\"/>\n", |
| 126 | + "<text xml:space=\"preserve\" text-anchor=\"middle\" x=\"109.36\" y=\"-71.19\" font-family=\"Times,serif\" font-size=\"14.00\">2</text>\n", |
| 127 | + "</g>\n", |
| 128 | + "<!-- 1--2 -->\n", |
| 129 | + "<g id=\"edge1\" class=\"edge\">\n", |
| 130 | + "<title>1--2</title>\n", |
| 131 | + "<path fill=\"none\" stroke=\"gray\" d=\"M35.61,-57.96C51.69,-61.94 75.33,-67.81 91.48,-71.81\"/>\n", |
| 132 | + "</g>\n", |
| 133 | + "<!-- 4 -->\n", |
| 134 | + "<g id=\"node3\" class=\"node\">\n", |
| 135 | + "<title>4</title>\n", |
| 136 | + "<ellipse fill=\"lightblue\" stroke=\"black\" cx=\"64.17\" cy=\"-18\" rx=\"18\" ry=\"18\"/>\n", |
| 137 | + "<text xml:space=\"preserve\" text-anchor=\"middle\" x=\"64.17\" y=\"-12.95\" font-family=\"Times,serif\" font-size=\"14.00\">4</text>\n", |
| 138 | + "</g>\n", |
| 139 | + "<!-- 1--4 -->\n", |
| 140 | + "<g id=\"edge2\" class=\"edge\">\n", |
| 141 | + "<title>1--4</title>\n", |
| 142 | + "<path fill=\"none\" stroke=\"gray\" d=\"M32.61,-42.33C38.1,-38.09 44.34,-33.28 49.81,-29.07\"/>\n", |
| 143 | + "</g>\n", |
| 144 | + "<!-- 3 -->\n", |
| 145 | + "<g id=\"node4\" class=\"node\">\n", |
| 146 | + "<title>3</title>\n", |
| 147 | + "<ellipse fill=\"lightblue\" stroke=\"black\" cx=\"63.48\" cy=\"-112.25\" rx=\"18\" ry=\"18\"/>\n", |
| 148 | + "<text xml:space=\"preserve\" text-anchor=\"middle\" x=\"63.48\" y=\"-107.2\" font-family=\"Times,serif\" font-size=\"14.00\">3</text>\n", |
| 149 | + "</g>\n", |
| 150 | + "<!-- 2--3 -->\n", |
| 151 | + "<g id=\"edge3\" class=\"edge\">\n", |
| 152 | + "<title>2--3</title>\n", |
| 153 | + "<path fill=\"none\" stroke=\"gray\" d=\"M94.84,-87.64C89.38,-91.92 83.18,-96.79 77.74,-101.05\"/>\n", |
| 154 | + "</g>\n", |
| 155 | + "<!-- 3--4 -->\n", |
| 156 | + "<g id=\"edge4\" class=\"edge\">\n", |
| 157 | + "<title>3--4</title>\n", |
| 158 | + "<path fill=\"none\" stroke=\"gray\" d=\"M63.61,-94.08C63.73,-77.49 63.91,-53.1 64.03,-36.44\"/>\n", |
| 159 | + "</g>\n", |
| 160 | + "</g>\n", |
| 161 | + "</svg>\n" |
| 162 | + ], |
| 163 | + "text/plain": [ |
| 164 | + "GraphNode({1: [2, 4], 2: [1, 3], 3: [2, 4], 4: [1, 3]})" |
| 165 | + ] |
| 166 | + }, |
| 167 | + "execution_count": 3, |
| 168 | + "metadata": {}, |
| 169 | + "output_type": "execute_result" |
| 170 | + } |
| 171 | + ], |
| 172 | + "source": [ |
| 173 | + "result = Solution().clone_graph(node)\n", |
| 174 | + "result" |
| 175 | + ] |
| 176 | + }, |
| 177 | + { |
| 178 | + "cell_type": "code", |
| 179 | + "execution_count": 4, |
| 180 | + "id": "test", |
| 181 | + "metadata": {}, |
| 182 | + "outputs": [], |
| 183 | + "source": [ |
| 184 | + "if result is None:\n", |
| 185 | + " assert node is None\n", |
| 186 | + "else:\n", |
| 187 | + " assert result.is_clone(node)" |
| 188 | + ] |
| 189 | + } |
| 190 | + ], |
| 191 | + "metadata": { |
| 192 | + "kernelspec": { |
| 193 | + "display_name": "leetcode-py-py3.13", |
| 194 | + "language": "python", |
| 195 | + "name": "python3" |
| 196 | + }, |
| 197 | + "language_info": { |
| 198 | + "codemirror_mode": { |
| 199 | + "name": "ipython", |
| 200 | + "version": 3 |
| 201 | + }, |
| 202 | + "file_extension": ".py", |
| 203 | + "mimetype": "text/x-python", |
| 204 | + "name": "python", |
| 205 | + "nbconvert_exporter": "python", |
| 206 | + "pygments_lexer": "ipython3", |
| 207 | + "version": "3.13.7" |
| 208 | + } |
| 209 | + }, |
| 210 | + "nbformat": 4, |
| 211 | + "nbformat_minor": 5 |
| 212 | +} |
0 commit comments