[Leetcode] clone Graph

Source: Internet
Author: User

Clone an undirected graph. each node in the graph containsLabelAnd a list of itsNeighbors.


OJ's undirected graph serialization:

Nodes are labeled uniquely.

We use #As a separator for each node, and ,As a separator for node label and each neighbor of the node.

 

As an example, consider the serialized Graph{0, 1, 2 #1, 2 #2, 2}.

The graph has a total of three nodes, and therefore contains three parts as separated#.

    1. First node is labeled0. Connect Node0To both nodes1And2.
    2. Second node is labeled1. Connect Node1To Node2.
    3. Third node is labeled2. Connect Node2To Node2(Itself), thus forming a self-cycle.

 

Visually, the graph looks like the following:

       1      /      /       0 --- 2         /          \_/


Solution:
http://blog.csdn.net/fightforyourdream/article/details/17497883

[Leetcode] clone Graph

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.