Trust groups |
The personnel department of Association of Cookie Monsters (ACM) has noticed that the productivity of various work groups in the company is not as good as it could be. They have interviewed the employees in the affected groups and they have detected the root of the problem: trust (or, rather, the lack thereof). Some employees do not trust the rest of the group, and this is decreasing their motivation and happiness. The personnel department wants to solve this problem, and has decided to reorganize the groups so that they are stable, i.e., they are formed by people who trust each other. They have asked the employees, and they know the people each employee trusts directly. Moreover, if employee A trusts employee B and employee B trusts employee C, then employee A will trust employee C. And obviously, each employee trusts himself. They want to create as few groups as possible to reduce administration overhead (they also do not want to work too hard).
With this information they have contacted you, and asked you to write a program that finds the minimum number of stable groups that can be created.
The input will end with the ``phantom'' test case `0 0', which must not be processed.
For each test case, the output will be a line containing a positive integer representing the minimum number of stable groups of people that can be formed.
3 2 McBride, John Smith, Peter Brown, Anna Brown, Anna Smith, Peter Smith, Peter Brown, Anna 3 2 McBride, John Smith, Peter Brown, Anna Brown, Anna Smith, Peter McBride, John Smith, Peter 0 0
2 3