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__ = ('value', 'next') def __init__(self, value): self.value = value 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]) node = Node(x) if not lists[t]['head']: lists[t]['head'] = node lists[t]['tail'] = node else: lists[t]['tail'].next = node lists[t]['tail'] = node elif parts[0] == '1': t = int(parts[1]) current = lists[t]['head'] res = [] while current: res.append(str(current.value)) current = current.next print(' '.join(res)) elif parts[0] == '2': s = int(parts[1]) t = int(parts[2]) if not lists[s]['head']: continue if not lists[t]['head']: lists[t]['head'] = lists[s]['head'] lists[t]['tail'] = lists[s]['tail'] else: lists[t]['tail'].next = lists[s]['head'] lists[t]['tail'] = lists[s]['tail'] lists[s]['head'] = None lists[s]['tail'] = None
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.