Canadian Computing Competition: 2014 Stage 2, Day 1, Problem 3
As they usually do,
Robots accuse other robots of being werewolves and defend other robots by vouching for their innocence.
The werewolves know each other's identities and:
- A werewolf never accuses another werewolf;
- Any robot that a werewolf defends is another werewolf.
Civilians may accuse or defend either type of robot.
Additional constraints to make our task a bit easier:
- No robot is both accused and defended.
- No robot is accused or defended more than once.
- For a robot
to accuse or defend a robot , then .
You will be given all the accusations and defenses between
Input Specification
The first line contains three numbers (each separated by one space):
, the number of robots, followed by , the number of werewolves, followed by , the number of accusations/defenses.
The next
indicates that robot accused robot of being a werewolf; indicates that robot defended robot .
You may assume that for 20% of the marks for this problem,
Output Specification
Output the number of role assignments that are consistent with the given information. Since this number may be very large, you must output this answer modulo
Sample Input 1
2 1 1
D 1 2
Output for Sample Input 1
1
Explanation of Output for Sample Input 1
If robot
Sample Input 2
2 1 0
Output for Sample Input 2
2
Explanation of Output for Sample Input 2
With no information, either robot
Sample Input 3
3 2 2
A 1 2
D 1 3
Output for Sample Input 3
2
Explanation of Output for Sample Input 3
Either robot
Comments