I'm practicing solving programming problems in free time. This problem I spotted some time ago and still don't know how to solve it:
For a given undirected graph with n vertices and m edges (both less than 2 × 106) I need to split its vertices into as many groups as possible, but with one condition: each pair of vertices from different groups are connected by edge. Each vertex is in exactly one group. At the end I need to know the size of each group.
I was proud when I came up with this solution: consider complemented graph of the original graph and use Disjoint-set data structure for it. It gives us the right answer (not difficult to prove). But it's only theoretical solution. With given constraints it's very very bad, not optimal. But I believe this approach can be somehow smartly fixed. But how?
Can anyone help?
EDIT: for a graph with vertices from 1 to 7 and 16 edges:
1 3
1 4
1 5
2 3
3 4
4 5
4 7
4 6
5 6
6 7
2 4
2 7
2 5
3 5
3 7
1 7
we have 3 groups with sizes: 1, 2 and 4.
These groups are: {4}, {5,7}, {1,2,3,6} respectively. There are edges connecting each pair of vertices from different groups and we can't create more groups.
each pair of vertices from different groups are connected by edge, do you mean they're connected by, at most, one edge? and, if not, from each pair of vertices from different groups must have an edge, do you mean if you have groupsA{a, b}, B{c, d}then there must be edges fromatocandd, and frombtocandd? - Rubensa-cora-d, right? or do the vertices in the same group must have edges in between them? - Rubens