#P1701. Valid Evolutionary Tree

    ID: 14986 Type: Default 1000ms 256MiB

Valid Evolutionary Tree

Valid Evolutionary Tree

It is the year 3019. Over the past millennium, countless evolutionary events have endowed cows with various unique features. The entire evolutionary history can be represented as a tree. The tree's root is the original cow with no special features. Each internal node in the tree may either represent a point where all descendant cows evolve a new feature (for example, fire breathing) or represent a branching evolution in which only some branches acquire a new feature (for example, flying). The leaves of the tree represent the cow subpopulations in the year 3019. No two different subpopulations have an identical set of features. A legal evolutionary tree is one where each newly evolved feature appears exactly once in the tree (i.e. it originates on a unique edge). For instance, if the feature "spots" evolved on two separate branches, the tree would not be considered legal.

Given the description of cow subpopulations and their features, determine whether these subpopulations can be explained by some legal evolutionary tree.

Formal Description:

You are given n cow subpopulations. Each subpopulation is described by a set of features. For any two distinct features \(f\) and \(g\), let \(S_f\) and \(S_g\) represent the sets of subpopulations that possess these features. The evolutionary tree is valid if and only if for every pair \(f, g\) with \(S_f \cap S_g \neq \emptyset\), we have \(S_f \subseteq S_g\) or \(S_g \subseteq S_f\). Output "yes" if a valid evolutionary tree can explain the subpopulations, and "no" otherwise.

inputFormat

The first line contains a single integer (n) ((1 \le n \le 10^5)), the number of cow subpopulations. Each of the following (n) lines describes a subpopulation. Each line begins with an integer (k) ((0 \le k \le 50)), followed by (k) space-separated strings representing the features of that subpopulation. Each feature is a lowercase string with a maximum length of 20.

outputFormat

Output a single line containing "yes" if it is possible to form a legal evolutionary tree that explains the subpopulations' features, or "no" otherwise.

sample

4
0
1 flying
1 telepathic
2 flying telepathic
yes

</p>