Problem A
Through the Grapevine

According to Wikipedia, to hear something “through the grapevine” is to learn of something informally and unofficially by means of gossip or rumor. In this problem, you are tasked with determining how many people will hear about a particular rumor “through the grapevine” after a certain number of days.
Rumors are always started by a single person. On any given day, a person who knows the rumor can spread it by telling the people that they know. Upon hearing of the rumor, that person must wait until the following day before they can begin to spread it themselves. Furthermore, some people are skeptical and will only spread the rumor once they’ve heard it from a number of distinct sources. However once a person has heard the rumor from enough people, they will always try to spread the rumor to as many people as possible.
Input
The first line will contain three integers:
The next
This is followed by
The final line will contain a single string
Output
Output a single integer: the number of people (not including
person
Sample Input 1 | Sample Output 1 |
---|---|
3 2 1 Alice 0 Bob 1 Carol 1 Alice Bob Bob Carol Alice |
1 |
Sample Input 2 | Sample Output 2 |
---|---|
5 5 3 Alice 0 Bob 1 Carol 1 Dan 3 Erin 1 Alice Bob Alice Carol Bob Dan Carol Dan Dan Erin Alice |
3 |