def gardenNoAdj(N, paths): # Adjacency list for the graph graph = [[] for _ in range(N)] # Populate the adjacency list for u, v in paths: graph[u - 1].append(v - 1) graph[v - 1].append(u - 1) # Result array to store the flower type for each garden res = [0] * N # Assign flower types for garden in range(N): # Find out the types of flowers used by neighboring gardens used = [0] * 5 for neighbor in graph[garden]: used[res[neighbor]] = 1 # Assign the smallest type of flower that is not used by neighbors for flower in range(1, 5): if not used[flower]: res[garden] = flower break return res

# Example usage T = 2 test_cases = [ (4, [[1, 2], [3, 4]]), (3, [[1, 2], [2, 3], [3, 1]]), ]

for n, paths in test_cases: print(gardenNoAdj(n, paths))