| 2026 Spring UT CS104c Midterm #1 |
|---|
| Закончено |
How often has this happened to you: you are trying to plan a group movie night, so you ask your friends if they'd like to join. "Well, I'm really busy with CS429 homework. But maybe if Cooper and Ava also come..."
You are given a list of friends, and for each friend, their dependencies. Each friend will attend the movie night if and only if all of their dependencies also attend.
You also have a list of best friends you definitely want there.
What is the minimum number of people you need to invite to the movie night so that your best friends attend?
The first line of input contains a single integer $$$n$$$ $$$(1 \leq n \leq 100)$$$, the number of potential friends you could invite to the movie night. The next $$$n+1$$$ lines describe you and your friends. Each line begins with a string of between $$$2$$$ and $$$10$$$ ASCII uppercase and lowercase letters; this string is the name of one friend. Then follows an integer $$$k$$$ ($$$0 \leq k \leq n$$$), the number of people on that friend's list of dependencies. The line ends with $$$k$$$ space-separated strings, the names of the friends on the dependency list.
One row starts with the name You. The dependencies of You are the friends you want to be sure attend the movie night.
No two rows start with the same string. Every string in every dependency list is the name of somebody with a row in the input. Nobody is on their own dependency list, and the same name doesn't appear twice on any one dependency list.
Print the minimum number of friends you need to invite (not including You) to guarantee that the people on You's dependency list show up.
4Brad 2 Cooper AvaCooper 0Ava 2 Brad YouAnnie 2 Brad CooperYou 1 Brad
3
3Yingying 2 You LuisLuis 2 Yingying MingyuYou 0Mingyu 1 Luis
0
| Название |
|---|


