You are given n gardens labeled from 1 to n, and an array paths where each element paths[i] = [xᵢ, yᵢ] represents a bidirectional path between garden xᵢ and garden yᵢ.
Each garden can be planted with one of four types of flowers (represented by numbers 1, 2, 3, 4).
Your goal is to assign a flower type to each garden such that:
• No two connected gardens (with a path between them) have the same flower type.
• Each garden must have exactly one flower type.
It is guaranteed that a valid assignment exists since each garden connects to at most three others.
Input: n = 3 paths = [[1,2],[2,3],[3,1]]
Output: [1,2,3]
Input: n = 4 paths = [[1,2],[3,4]]
Output: [1,2,1,2]
Accepted:
Submission: