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
pythonn, q = map(int, input().split()) lists = [(None, None) for _ in range(n)] for _ in range(q): query = list(map(int, input().split())) if query[0] == 0: t = query[1] x = query[2] new_node = [x, None] head, tail = lists[t] if head is None: lists[t] = (new_node, new_node) else: tail[1] = new_node lists[t] = (head, new_node) elif query[0] == 1: t = query[1] head, tail = lists[t] elements = [] current = head while current: elements.append(str(current[0])) current = current[1] print(' '.join(elements)) elif query[0] == 2: s = query[1] t = query[2] s_head, s_tail = lists[s] t_head, t_tail = lists[t] if s_head is None: continue # According to constraints, s is not empty if t_head is None: lists[t] = (s_head, s_tail) else: t_tail[1] = s_head lists[t] = (t_head, s_tail) lists[s] = (None, None)
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.