Clone an undirected graph. Each node in the graph contains a label and a list of its neighbors.
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 by#.
First node is labeled as 0. Connect node 0 to both node s1 and 2. Second node is labeled as 1. Connect node 1 to node 2. Third node is labeled as 2. Connect node 2 to node2(itself), thus forming a self-cycle.
Visually, the graph looks like the following:
复制一个无向图,图中的每一个节点都有一个标签,以及其若干个邻居节点。 OJ的无向图序列: 节点被唯一标志 我们使用#作为每一个节点的分隔符以及节点和其邻居节点的分隔符 比如,考虑一个{0,1,2# 1,2# 2,2}序列 该图一共有3个节点,被#分隔为3个部分 第一个节点的标志是0,连接节点1和节点2 第二个节点是1,连接节点1和节点2 第三个节点是2,连接节点2和节点2(自己),即形成了一个自环 将上图可视化出来就是这样的: