Rock Paper Scissors Strategy
Time limit1sMemory limit1024 MB
Given N players and M games with participant lists and winners, count the strategy assignments (fixed hand, or cyclic RPS pattern) consistent with all results, modulo 1e9+7.
- Level
Hard8 of 10
- Topics
- Implementation, Brute force, Math
- Solved
- No attempts yet
Problem
Yunee, the president of the UNIST Rock-Paper-Scissors Association, held a rock-paper-scissors contest for UNIST students and gathered participants. The contest consists of games in total. In each game, two or three participants make one of the three hand gestures, rock, paper, or scissors, all at once. Then the winner of each game is determined according to the following rules.
- Rock wins scissors, scissors win paper, and paper wins rock.
- If everyone makes the same hand gesture, the game draws.
- If all three types of hand gestures appear, the game draws.
- If the game doesn't draw, everyone who makes a winning hand gesture wins.
Each UNIST student had prepared one of the following strategies for this contest.
- Always play the same hand gesture.
- Play the three hand gestures once each, in any order. Repeat the same pattern for every three games this player participates in.
Unfortunately, Yunee couldn't watch the contest because of a lot of paperwork. But Yunee has a document that lists the participants and the winners of each game. Yunee wondered what strategies the students might have used. Find the number of possible strategy combinations of all students, modulo .
Input
The first line contains two integers and . represents the number of participants of the contest. represents the number of games.
The next lines contain the descriptions for the games in chronological order. Each game is described as follows.
- The number of participants is given.
- The participants' numbers are given. They are distinct integers ranging from to .
- A delimiter
/is given. - The number of winners is given. If the game draws, .
- The winners' numbers are given. They are distinct integers among .
Output
Output the number of possible strategy combinations of all students, modulo .