Example Input 2 2 2 4 0 0 0 1 1 0 1 0 1 0 1 1 Output 4
- User
Example Input
2 2 2 4 0 0 0 1 1 0 1 0 1 0 1 1
Output
4
Assistant
pythonfrom collections import deque # Read input x, y, z, k = map(int, input().split()) cells = set() for _ in range(k): a, b, c = map(int, input().split()) cells.add((a, b, c)) # Define directions for adjacent cells directions = [(1, 0, 0), (-1, 0, 0), (0, 1, 0), (0, -1, 0), (0, 0, 1), (0, 0, -1)] visited = set() component_count = 0 for cell in cells: if cell not in visited: component_count += 1 queue = deque([cell]) visited.add(cell) while queue: current = queue.popleft() for dx, dy, dz in directions: neighbor = (current[0] + dx, current[1] + dy, current[2] + dz) if neighbor in cells and neighbor not in visited: visited.add(neighbor) queue.append(neighbor) print(component_count)
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.