Nine Chapters count judges Net-original website
http://www.jiuzhang.com/problem/61/
Topics
A graph is given and the starting node of the graph is given, and the definition of the node of the graph is required to clone the graph and return the starting node of the clone graph.
Online test
http://www.lintcode.com/en/problem/clone-graph/
Answer
This type of cloning a graph of the topic, we can be divided into two steps.
First step: Clone the point. Just use the breadth-first search method to traverse through the graph from the root node, and clone each point a corresponding clone point a ' is stored in the map, so the map stores the corresponding clone points for each point.
Step two: Clone edges. Then use the breadth-first search method to traverse through the graph, and this time because know a point a of the neighboring point B, and map stored a clone point a ', B's clone point B ', so this time also know a ' and B ' is the adjacent point, the establishment of clone edge.
This allows for a complete clone of a diagram with these two steps.
Nine chapters algorithm surface question 61 clone diagram