You are given an undirected graph and an integer k. Determine whether it is possible to assign one of k colors to every node so that no two nodes connected by an edge share the same color.
Input Description:
n — the number of nodes.k — the number of available colors.(u, v) of distinct integers from 0 to n-1.Output Description:
True if a valid k-coloring exists; otherwise, return False.Example:
Input: n = 3, k = 3, edges = [[0, 1], [1, 2], [2, 0]]
Output: True
Explanation: The graph is a triangle. With three colors available, we can give each node a distinct color, satisfying the constraint.
Constraints:
1 <= n <= 10000 <= k <= nn