Tournament Matchmaking
시간 제한3초메모리 제한2048 MB
각 선수가 15개 역할 중 두 개를 맡을 수 있을 때, 두 그룹을 합쳐 15개 역할이 모두 서로 다른 선수로 채워지는 팀을 최대한 많이 만든다.
문제
You are organizing a recreational rugby tournament. A rugby team has distinct roles, numbered to . Each team in the tournament must have exactly players, each fulfilling one of the roles. Although several groups of friends showed up to play in the tournament, none of the groups are large enough to form a complete team. You would like to create teams by merging some pairs of groups together.
Each group has between and players (inclusive) and you know that each player has exactly potential roles they could play on a team. Determine the maximum number of valid teams you can form. A team is valid if it is made of exactly two groups, it has exactly players (no more, no fewer), and every role on the team is played by a different player able to play that role. A group cannot be part of more than one team.
입력
The first line contain a single integer , the number of groups.
Following this line are group descriptions. The first line of a group description contains a single integer , the size of the group. The following lines each contain two space-separated integers and , representing a player that can fulfill either role or role on team.
출력
Output the maximum number of valid teams that can be created by merging pairs of groups together.