Pod Placement Planner
Your team is shrinking a staging cluster and wants to know how few machines it really needs. All
nodes in the cluster have the same capacity: C millicores of CPU and M MiB of memory.
There are n pods to schedule. Pod i requests c_i millicores and m_i MiB. Every pod must be
placed on exactly one node, and on each node the total CPU requested by its pods must not exceed
C, and the total memory must not exceed M.
Some pods are replicas of the same service and carry an anti-affinity rule: for each of the p
listed pairs (a, b), pods a and b must run on different nodes.
Find the minimum number of nodes needed to place all pods, together with one placement that
achieves it. If some pod cannot fit on a node even when it runs alone, print -1.
Input
The first line contains four integers n, p, C and M (1 ≤ n ≤ 15, 0 ≤ p ≤ n·(n−1)/2,
1 ≤ C, M ≤ 10^6).
Each of the next n lines contains two integers c_i and m_i (1 ≤ c_i, m_i ≤ 10^6): the CPU and
memory requests of pod i.
Each of the next p lines contains two integers a and b (1 ≤ a, b ≤ n, a ≠ b): pods a and b
must not share a node. No unordered pair is listed twice.
Output
If some pod has c_i > C or m_i > M, print a single line -1.
Otherwise print the minimum number of nodes k on the first line. On the second line print n
integers x_1, x_2, …, x_n (1 ≤ x_i ≤ k), where x_i is the node that pod i is placed on. The
placement must respect both capacities on every node and every anti-affinity rule. If several
placements use k nodes, print any of them.
Notes
In the first example, pods 1 and 2 are anti-affine, so at least two nodes are needed. Two nodes suffice: pods 1 and 3 use 900 millicores and 800 MiB, pods 2 and 4 use 900 millicores and exactly 1000 MiB. Placing pods 3 and 4 together would not work, since they need 1100 MiB.
In the second example, pod 3 asks for more memory than a single node has, so no placement exists.