Win
Time limit2sMemory limit512 MB
Given a league with at most 20 unplayed games, count the distinct win-loss outcomes of those games where the favorite team finishes in sole first place.
- Level
Medium4 of 10
- Topics
- Brute force, Bit manipulation
- Solved
- No attempts yet
Problem
Song-i is a baseball fan. She wants her favorite team to finish first, so she predicts the results of the remaining games to see where her team stands.
The league has games in total. Each game has two teams. There are no draws, so one team always wins and the other loses. The winning team gets 1 point. To take sole first place in the league, a team must have the highest points among all teams, and no other team may have the same points.
Count the number of ways her favorite team can take sole first place. Two orders of playing the games count as one case if the results are the same.
Input
The first line contains three integers , , and , separated by spaces: the number of teams, the number of games, and the team number of Song-i's favorite team.
Each of the next lines describes a game in the form (team 1, team 2, result). Team numbers are integers from to , and team 1 and team 2 are always different. The result is if the game has not been played yet, if team 1 won, and if team 2 won. At most games have not been played yet. Her favorite team may not appear in the input.
All numbers in the input are integers.
Output
Print the number of ways her favorite team can take sole first place after all unplayed games are finished.