Some Disguised Bi-partite Graphs
by p_square, May 23, 2019, 11:25 AM
This blog post will feature grids and a popular technique involving bipartite graphs to solve some grid related questions.
The main idea will be to treat every row and column of a grid as a vertex of a graph and join two vertices representing a row and a column by an edge depending on their intersection.
Since the exact technique is hard to rigourize in such a manner, I'll present a problem and its solution to convey the main idea.
Let us reformulate the problem into a statement that involves a bipartite graph.
Let
be the set of vertical lines passing through at least one point of the set.
Let
be the set of horizontal lines passing through at least one point of the set.
Consider the bipartite graph
with consisting of lines with the bipartition
and
.
Let two lines in
and
be neighbours if they intersect at a point in the given set of points.
We wish to colour the edges in such a manner that the differences between red edge degree an white edge degree of a vertex is at most
.
First of all, note that all cycles have even length.
What this means, is that we can remove an arbitrary cycle by colouring its edges red and white in an alternating manner.
We are left with a forest.
Consider any tree of the forest. Give it an arbitrary root.
It can be seen inductively that given any tree rooted at
and a weight
which is either
or
we can colour the edges of the tree red and white in such a way that
number of red edges to
- number of white edges to 
(This is because we can first make sure that the root is happy
).
for every other vertice v, the difference between red and white edges is in
. \blacksquare
The next example in store is from PSE.
Note that there are finitely many possibilities for the initial configuration of bacteria. This reduces the problem to a simple application of Govind's lemma
The solution provided in the link is quite ingenious and quite hard to come up with. Here is a more natural way to solve the problem.
Create a bipartite graph whose vertices are rows and columns of the chessboard and join two vertices by an edge iff they intersect at an infected cell.
Since there are only 14 edges, observe that the graph is disconnected.
Every second, we add some edge to the graph.
However observe that if two vertices were in different components, we cannot add an edge joining them! Whenever we add an edge between two vertices, there must have been a path of length 3 connecting these 2 vertices.
Since initially our graph was disconnected, it will stay disconnected forever; it can never become a complete bipartite graph.. \blacksquare
For the informatics variant and a minor generalisation, check here
pro yaar god yaar. Found white text yaar
While grid bipartition did come useful when solving the previous two questions, it's true power was not revealed.
Grid bipartition can let us turn all of the powerful theorems on graphs quickly to our advantage just by reformulating the question slightly.
It isn't hard to come up with questions like this.
For example (mine)
Another example (again mine)
___________________________________________________________________
These grid based questions also combine well with the study of matching's in graph theory.
An example can be seen in this question here.
Let the columns and rows represent vertices of a bipartite graph
with vertices
and
. The edge
iff there is a stone at the intersection of the
row and
column. Notice that the degree of a vertex in
or
is the number of stones in that row or column respectively. We need to show that there exists an edge
such that
.
Assume the contrary and consider the counter example that minimises
. If
then
. We can assume
is connected else we would be done by the minimality of our counter example. We will show that there is a matching of
onto
. (that is, a set of
edges, such that each vertex in
is adjacent with exactly one edge).
Suppose we have a matching,
with maximum number of edges. If the matching is not complete from
, then
and
are non-empty. Suppose
, by the condition,
must be adjacent to some other vertex in
. If
we're done. Otherwise
, let
be the corresponding edge of
in
. We see that
has degree at least
, so
has degree at least
, by the condition, so
is adjacent to another vertex
.
We continue in the manner. Since
is finite and connected we must eventually reach a vertex
. We can assume the path
passes each vertex only once, else we contract any closed loop. Since the path is odd, say length
, there are exactly
edges on the path that are in
. Then if we delete those edges we are left with
disjoint edges; that is, another matching with more edges. this contradicts the maximality of
. It follows that we can find a complete matching 
Now each edge
satisfies
. But since
there is some
, and
. Hence
, but this is absurd. So there is no counter example, and we're done.
[Credits of the solution to Ocha]
Hall's marriage lemma (put simply without symbols) states that in a bipartite graph, iff for every subset of vertices which are of the same colour, the size of the set that consists of ala their neighbours is greater than the original size of the set, then there is a perfect matching on the graph.
Hall's marriage lemma (put simply with symbols) states that in a graph
with bipartition
or
a perfect matching.
This too is a formidable tool in the powerful arsenal of grid bipartition. India TST 2017/1/3 falls prey to this.
We will induct on the common sum of all rows/columns.
Define the bipartite multi(!)-graph G in a manner similar to the start of every problem ever in this post. [join with size of intersection]
Given any
rows/columns
edges emanate and since each column/row swallows at most
, we see that by Hall's matching thm. a perfect matching exists.
The last example [again delving into Hall's thm] is RMM 2017/5.
The answer as one learns after drawing a lot of sieves is
.
The construction for
is easy, irrelevant and left to the reader as an exercise. The interesting part is the proof for minimality..
There are easier 'local' proofs where one can delete a row or column but we present a better, more elegant proofno, I'm not biased at all.
Don't Create a bipartite graph for once.
Let
be the set of
sticks that are either to the left of a removed cell (and stretch till the left edge) or to the right (and stretch till the end of a removed cell) of a removed cell.
Let
be the set of
sticks that are either above a removed cell (and stretch till he top edge) or below a removed cell (and stretch till the bottom edge).
Connect a pair of vertices in
with an edge if they intersect.
Each edge corresponds to an unblocked cell.
We will now demonstrate Hall's criterion to show that perfect matching exists between vertices in
.
This will finish the problem as then select the
cells that correspond to edges of the perfect matching. No pair of these
cells can lie on the same stick.
For any
and
vertices in
, there must be some
sticks that terminate at the right edge of the
grid and
sticks terminating at the left edge.
Thus, the
leftmost columns each must have a stick in
that intersects with the largest of the
sticks terminating at the left edge.
Similarly, each of the
rightmost columns each must have a stick in
that intersects wit the largest of the
sticks terminating at the right edge.
Thus, there must be at least
vertices in
that are connected to at least one of the vertices in
.
For any
, and any subset of
with size
, it is not hard to see that the subset of
in which each vertex is connected to at least one of the
sticks in
has size greater than
by looking at the vertices in
with which the compliment of this subset of
and doing the same this as the case when
and creating a record for the longest and most confusing sentence.
___________________________________________________________________
Practice Problems:
I actually haven't done the third problem, so don't blame me if there is no solution
___________________________________________________________________
PS I recently read a book 'All the Light We Cannot See' by 'Anthony Doerr' which turned out to be really good. People should try it if they can. To provide some motivation: It won the Pulitzer Prize for fiction in 2015.
The main idea will be to treat every row and column of a grid as a vertex of a graph and join two vertices representing a row and a column by an edge depending on their intersection.
Since the exact technique is hard to rigourize in such a manner, I'll present a problem and its solution to convey the main idea.
IMO 1986/6 wrote:
Given a finite set of points in the plane, each with integer coordinates, is it always possible to color the points red or white so that for any straight line
parallel to one of the coordinate axes the difference (in absolute value) between the numbers of white and red points on
is not greater than
?



Let us reformulate the problem into a statement that involves a bipartite graph.
Let

Let

Consider the bipartite graph



Let two lines in


We wish to colour the edges in such a manner that the differences between red edge degree an white edge degree of a vertex is at most

First of all, note that all cycles have even length.
What this means, is that we can remove an arbitrary cycle by colouring its edges red and white in an alternating manner.
We are left with a forest.
Consider any tree of the forest. Give it an arbitrary root.
It can be seen inductively that given any tree rooted at




number of red edges to


(This is because we can first make sure that the root is happy

for every other vertice v, the difference between red and white edges is in

The next example in store is from PSE.
Infected Checkerboard Variant wrote:
There are
bacteria on a checkerboard. If in a 2x2 sub-board, 3 cells are infected, the 4th cell gets infected from the next second. Infected cells remain infected. Is it possible that eventually the whole checkerboard gets infected?

The solution provided in the link is quite ingenious and quite hard to come up with. Here is a more natural way to solve the problem.
Create a bipartite graph whose vertices are rows and columns of the chessboard and join two vertices by an edge iff they intersect at an infected cell.
Since there are only 14 edges, observe that the graph is disconnected.
Every second, we add some edge to the graph.
However observe that if two vertices were in different components, we cannot add an edge joining them! Whenever we add an edge between two vertices, there must have been a path of length 3 connecting these 2 vertices.
Since initially our graph was disconnected, it will stay disconnected forever; it can never become a complete bipartite graph.. \blacksquare
For the informatics variant and a minor generalisation, check here
pro yaar god yaar. Found white text yaar
While grid bipartition did come useful when solving the previous two questions, it's true power was not revealed.
Grid bipartition can let us turn all of the powerful theorems on graphs quickly to our advantage just by reformulating the question slightly.
It isn't hard to come up with questions like this.
For example (mine)
Tweaked Konig's wrote:
Some stones were places in a rectangular grid. Let
be the smallest natural number such that given any
stones, some two are either in the same row or same column. In one step, Petya removes all stones in row or column. Prove that the minimum number of steps required by Petya to remove all the stones is
.



Another example (again mine)
Tweaked edge coloring wrote:
Some rooks were placed on a
chessboard, such that no row or column contained more than
rooks. Prove that we can assign each rook one of
colours such that no two rooks of the same color attack each other (For this problem, assume that rooks can attack over other rooks)



___________________________________________________________________
These grid based questions also combine well with the study of matching's in graph theory.
An example can be seen in this question here.
AoPS post wrote:
Some cells of a rectangular table with
rows and
columns (
) is filled with stones such that there is at least
stone in any column. Prove that there is a stone such that the number stones of row has it greater than the number stones of column has it.




Let the columns and rows represent vertices of a bipartite graph










Assume the contrary and consider the counter example that minimises








Suppose we have a matching,


















We continue in the manner. Since









Now each edge






[Credits of the solution to Ocha]
Hall's marriage lemma (put simply without symbols) states that in a bipartite graph, iff for every subset of vertices which are of the same colour, the size of the set that consists of ala their neighbours is greater than the original size of the set, then there is a perfect matching on the graph.
Hall's marriage lemma (put simply with symbols) states that in a graph




This too is a formidable tool in the powerful arsenal of grid bipartition. India TST 2017/1/3 falls prey to this.
India TST 2017/1/3 wrote:
Let
be a positive integer. An
matrix is called good if each entry is a non-negative integer, the sum of entries in each row and each column is equal. A permutation matrix is an
matrix consisting of
ones and
zeroes such that each row and each column has exactly one non-zero entry.
Prove that any good matrix is a sum of finitely many permutation matrices.





Prove that any good matrix is a sum of finitely many permutation matrices.
We will induct on the common sum of all rows/columns.
Define the bipartite multi(!)-graph G in a manner similar to the start of every problem ever in this post. [join with size of intersection]
Given any



The last example [again delving into Hall's thm] is RMM 2017/5.
RMM 2017/5 wrote:
Fix an integer
. An
sieve is an
array with
cells removed so that exactly one cell is removed from every row and every column. A stick is a
or
array for any positive integer
. For any sieve
, let
be the minimal number of sticks required to partition
. Find all possible values of
, as
varies over all possible
sieves.













The answer as one learns after drawing a lot of sieves is

The construction for

There are easier 'local' proofs where one can delete a row or column but we present a better, more elegant proof
Let


Let


Connect a pair of vertices in

Each edge corresponds to an unblocked cell.
We will now demonstrate Hall's criterion to show that perfect matching exists between vertices in

This will finish the problem as then select the


For any






Thus, the



Similarly, each of the



Thus, there must be at least



For any










___________________________________________________________________
Practice Problems:
- EGMO 2013/3
Letbe a positive integer. Consider a
array of square unit cells. Two different cells are related to each other if they are in either the same row or in the same column.No cell is related to itself.Some cells are coloured blue, such that every cell is related to at lest two blue cells.Determine the minimum number of blue cells.
- Kazakhstan 2012 9.6
The cell of aboard are painted in two colors - white and black. The unit cell of a row (column) is called dominant on the row (the column) if more than half of the cells that row (column) have the same color as this cell. Prove that at least
cells on the board are dominant in both their row and column.
- Belarusian National Olympiad 2007/3
Given atable
with one of two signs ”+” or ”-” in each of its cells. A union of all the cells of some row and some column is called a cross. The cell on the intersection of this row and this column is called the center of the cross. The following procedure we call a transformation of the table: we mark all cells which contain ”−” and then, in turn, we replace the signs in all cells of the crosses which centers are marked by the opposite signs. (It is easy to see that the order of the choice of the crosses doesn’t matter.) We call a table attainable if it can be obtained from some table applying such transformations one time.
Find the number of all attainable tables.
I actually haven't done the third problem, so don't blame me if there is no solution

___________________________________________________________________
PS I recently read a book 'All the Light We Cannot See' by 'Anthony Doerr' which turned out to be really good. People should try it if they can. To provide some motivation: It won the Pulitzer Prize for fiction in 2015.
This post has been edited 5 times. Last edited by p_square, May 23, 2019, 1:23 PM