← 返回 meta 的题目列表Deep Copy a Graph
类型:online_judge
Implement a function to deep copy an undirected graph, where each node contains an integer value and a list of neighbors. The undirected graph is represented as an adjacency list, for example, the graph
1 -- 2
| |
3 -- 4
can be represented as {1 [2, 3], 2 [1, 4], 3 [1, 4], 4 [2, 3]}.
Input/Output Specification
Input: Starting node of the undirected graph (node, Node type)
Output: Starting node of the deep copied graph.
Example
Input: {1 [2, 3], 2 [1, 4], 3 [1, 4], 4 [2, 3]} Output: A new graph identical in structure to the input but with different address.
Example
Input
{1 [2, 3], 2 [1, 4], 3 [1, 4], 4 [2, 3]}