Science!
Time limit3sMemory limit128 MB
Given a bipartite allowance graph on n people and n buttons, find the largest number of edge-disjoint perfect matchings (a maximum k-regular subgraph).
- Level
Medium7 of 10
- Topics
- Graph, Combinatorics, Math, Implementation
- Solved
- No attempts yet
Problem
Welcome to Aperture Science. For the experiment we have gathered people and buttons.
In each round, every person must stand on exactly one button, and no two people may share a button — so a single round is a one-to-one assignment of people to buttons. A person may only stand on the buttons they are cleared for.
We want to repeat this as many times as possible. The one extra rule is that, across all rounds, no person may ever stand on the same button more than once. Given who is cleared for which button, determine the maximum number of rounds that can be performed.
Input
The input contains several test cases. The first line of each case contains an integer (), the number of people (which equals the number of buttons). Each of the next lines contains characters. If the -th character of the -th line is Y, person is allowed to stand on button ; otherwise it is N. A line containing a single 0 terminates the input.
Output
For each test case, output a single line containing : the maximum number of rounds that can be performed so that in every round each person stands on a button they are allowed to use, each button holds exactly one person, and no person ever stands on the same button in two different rounds. This value may be .