PIXELBANKv8.2.1
Menu

Clone Graph

Given an adjacency list representation of an undirected graph, create a deep copy (clone) of the graph.

Input: each line is a node's neighbors as comma-separated indices (1-indexed). Output the same adjacency list.

Example:

Input:
2,4
1,3
2,4
1,3
Output:
2 4
1 3
2 4
1 3
Reasoning:
  • The input represents an adjacency list of a graph, where each line corresponds to a node and its neighbors.
  • The given input 2,4, 1,3, 2,4, 1,3 represents a graph with 4 nodes, where node 1 is connected to nodes 2 and 4, node 2 is connected to nodes 1 and 3, node 3 is connected to nodes 2 and 4, and node 4 is connected to nodes 1 and 3.
  • To create a deep copy of the graph, we simply replicate the adjacency list, resulting in the same connections between nodes.
  • The final output is the cloned adjacency list: 2 4, 1 3, 2 4, 1 3

Constraints:

  • 1 <= number of nodes <= 100
  • 0 <= number of edges
  • No self-loops or repeated edges
Editor

Test Results

0/0
Run code to see test results.