Tournament Matchmaking

시간 제한3초메모리 제한2048 MB

요약
각 선수가 15개 역할 중 두 개를 맡을 수 있을 때, 두 그룹을 합쳐 15개 역할이 모두 서로 다른 선수로 채워지는 팀을 최대한 많이 만든다.
난이도

어려움10점 중 8점

유형
그래프, 백트래킹, 비트 연산, 수학
정답자
아직 제출이 없습니다

문제

You are organizing a recreational rugby tournament. A rugby team has 1515 distinct roles, numbered 11 to 1515. Each team in the tournament must have exactly 1515 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 11 and 1414 players (inclusive) and you know that each player has exactly 22 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 1515 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 n(1≤n≤500)n (1 \le n \le 500), the number of groups.

Following this line are nn group descriptions. The first line of a group description contains a single integer k(1≤k≤14)k (1 \leq k \leq 14), the size of the group. The following kk lines each contain two space-separated integers aa and bb (1≤a<b≤15)(1 \leq a < b \leq 15), representing a player that can fulfill either role aa or role bb on team.

출력

Output the maximum number of valid teams that can be created by merging pairs of groups together.

예제1

  1. 예제 1

    입력
    5
    5
    4 8
    7 11
    6 8
    3 4
    4 9
    8
    6 9
    2 4
    2 9
    2 11
    2 11
    2 8
    2 14
    2 12
    7
    5 7
    1 2
    10 11
    1 3
    5 6
    4 13
    13 15
    1
    9 10
    10
    2 9
    1 3
    8 10
    1 9
    8 11
    1 5
    1 5
    1 6
    2 4
    2 3
    
    예상 출력
    1