For $n$ lists $L_i$ $(i = 0, 1, ..., n-1)$, perform a sequence of the following…
- User
For lists , perform a sequence of the following operations.
Assistant
pythonclass Node: __slots__ = ['val', 'next'] def __init__(self, val): self.val = val self.next = None n, q = map(int, input().split()) lists = [{'head': None, 'tail': None} for _ in range(n)] for _ in range(q): parts = input().split() if parts[0] == '0': t = int(parts[1]) x = int(parts[2]) new_node = Node(x) if lists[t]['head'] is None: lists[t]['head'] = new_node lists[t]['tail'] = new_node else: lists[t]['tail'].next = new_node lists[t]['tail'] = new_node elif parts[0] == '1': t = int(parts[1]) current = lists[t]['head'] res = [] while current is not None: res.append(str(current.val)) current = current.next print(' '.join(res)) elif parts[0] == '2': s = int(parts[1]) t = int(parts[2]) s_head = lists[s]['head'] s_tail = lists[s]['tail'] lists[s]['head'] = None lists[s]['tail'] = None if lists[t]['head'] is None: lists[t]['head'] = s_head lists[t]['tail'] = s_tail else: lists[t]['tail'].next = s_head lists[t]['tail'] = s_tail
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.