#P1701. [USACO19OPEN] Cow Evolution B
[USACO19OPEN] Cow Evolution B
Problem Description
It is now the year 3019. Over the past thousand years, countless evolutions of cows have occurred, producing dairy cows with all kinds of interesting traits.
The record of cow evolution can be represented by a tree. The origin is a cow with no special traits at the root of the tree. For each node in the tree that produces offspring, it is possible that all cows evolve a new trait (for example, fire breathing, as shown in the figure below, where all spotted cows eventually can breathe fire), or the cow population splits into branches, where some evolve a new trait (for example, flying) and some do not.

The leaf nodes at the bottom of the tree represent all subpopulations of cows that exist in the year 3019. No two different leaf nodes (subpopulations) have exactly the same set of traits. For example, subpopulation #1 consists of cows with no special traits, and subpopulation #3 consists of telepathic flying cows. In contrast, subpopulation #2 consists of cows that can fly but are not telepathic. Subpopulation #3 is the only one that is both flying and telepathic.
An evolutionary tree like the one above, where each newly evolved trait appears on exactly one edge in the tree (that is, it appears only once at a single point in time throughout the entire evolutionary history), is called “valid”. For example, if the trait spots evolves independently in two different branches, then the evolutionary tree is not valid. Given the descriptions of the cow subpopulations in the year 3019, determine whether they can be explained by a valid evolutionary tree.
Input Format
The first line of input contains the number of subpopulations (). The next lines each describe one subpopulation. Each line contains an integer (), followed by traits that the cows in this subpopulation have. Each trait is a string of at most lowercase letters (a..z). No two subpopulations have exactly the same traits.
Output Format
If it is possible to construct an evolutionary tree that can explain how all subpopulations arose, output yes; otherwise output no.
4
2 spots firebreathing
0
1 flying
2 telepathic flying
yes
Hint
Sample Explanation 1
This sample input matches the valid evolutionary tree shown in the figure above.
Translated by ChatGPT 5