Loading...
You are given an integer n and an array constraints, where constraints[i] = [t, a, b] links nodes a and b. There are n nodes labeled 1 to n, and each node must be assigned one of two colors:
t = 0, nodes a and b must get the same color;t = 1, nodes a and b must get different colors.Count the assignments of colors to all n nodes that satisfy every constraint, and return the count written in binary, as a string. If no assignment satisfies all constraints, return "0".
Input: n = 3, constraints = [[0, 1, 2], [1, 3, 2]]
Output: "10"
Explanation: Node 2 must match node 1 and differ from node 3, so all three
nodes form one linked group with exactly two valid colorings (pick either
color for node 1 and the rest follows). The count is 2, which is "10" in
binary.
Input: n = 4, constraints = [[1, 1, 2], [0, 2, 3], [1, 3, 4], [1, 1, 4]]
Output: "0"
Explanation: Following the first three constraints from node 1 forces node 4
to the same color as node 1, but the last constraint requires them to
differ. No assignment works.
n ≤105constraints.length ≤105t is 0 or 1; 1≤a,b≤ nClick "Run" to test with sample cases or "Submit" to run all tests.