PIXELBANKv9.1.0
Menu

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 <= neighbors per node <= 100
🔒

Editor locked

The code editor is locked for Pro problems. It is only available for free problems. Please upgrade to gain access to the code editor for all problems.

solution.py

Test Results

0/0
Run code to see test results.