Editorial for DMOPC '22 Contest 1 P3 - Group Project


Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.

Author: Riolku

Subtask 1 Hint 1

We have a definition from the statement that works on the graph, but not the one in the input. Try to find an equivalent characterization for the complement graph (the one in the input).

Subtask 1 Hint 2

Try drawing a complete graph of size 4 and remove edges until there are no friend groups.

Subtask 1

If there is a node v in the complement graph with at least two neighbours, and one of the neighbours u has at least two neighbours, there is no friend group. Suppose x is the other neighbour of v, and let y be the other neighbour of u. If x = y, our group of four is (v, u, x, w), where w is any other node. If x \ne y, our group of four is (v, u, x, y).

Implementing this gives us an \mathcal O(Q(N + M)) algorithm.

Subtask 2 Hint 1

Nothing particularly new needs to be done, all that needs to be done is figuring out how to maintain the information dynamically.

Subtask 2 Hint 2

Call a node heavy if it has at least two neighbours. Maintain the set of heavy nodes, along with another set.

Subtask 2 Hint 3

Call an edge strong if it connects two heavy nodes. If we have a strong edge, we can make a group without a friend group.

Subtask 2

The only missing piece of the puzzle is how to maintain this. We can use two sets. Updating the set of strong edges is cheap because whenever a node becomes heavy/light, there are only 1 or 2 neighbours to check and update.


Comments

There are no comments at the moment.