You are organizing a basketball tournament for teams from your neighborhood. An even number of teams, numTeams, has registered. You want the tournament to last numTeams - 1 rounds, where numTeams/2 matches are played simultaneously in each round. Each team must play each of the other teams exactly once during the tournament. You predict that some of the matches will be particularly exciting, so you want to schedule them during specific rounds.
You are given a String[] preferences, where each element is formatted:
<Round>:<TeamA>-<TeamB>
where <Round> is the zero-based number of the round, and <TeamA> and <TeamB> are zero-based team numbers. Return the number of different tournament schedules that will satisfy all the preferences. Return 0 if no schedule can satisfy all the preferences.
Two schedules A and B are different if there exists a round in which a team plays a different opponent in A than it does in B. For example, if the same round in two schedules are as follows:
schedule A schedule B
0-1 3-2
2-3 0-1
they are the same, but
schedule A schedule B
0-1 0-2
2-3 1-3
are different.
|