Nine chapters algorithm surface question 61 clone diagram

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.