Vital1ty's blog

By Vital1ty, 10 years ago, In English

Pls... help me out with this problem

http://www.spoj.com/problems/ANGELS/

It uses bipartite matching i guess. But am not able to build the graph .

  • Vote: I like it
  • 0
  • Vote: I do not like it

»
10 years ago, # |
  Vote: I like it +6 Vote: I do not like it

Your guess is absolutely correct. Consider vertical and horizontal segments formed by adjacent symbols 'A' in every row and in every column. If we want to place a "fighter" in some square (i, j), we can't place any "fighter" in vertical and in horizontal segments that (i,j) belongs to.

So, we need to make a bipartite graph where vertices are segments and edges are squares (i,j) where we can place a "fighter".

Maximal matching in this graph is the answer for the problem.