import sys def csr(n, E): start = [0] * (n + 1) elist = [0] * len(E) for e in E: start[e[0] + 1] += 1 for i in range(1, n + 1): start[i] += start[i - 1] counter = start[:] for e0, e1 in E: elist[counter[e0]] = e1 counter[e0] += 1 return start, elist class _SCC_graph: def __init__(self, n): self._n = n self.edges = [] sys.setrecursionlimit(max(2*n, sys.getrecursionlimit())) def num_vertices(self): return self._n def add_edge(self, frm, to): self.edges.append([frm, to]) def scc_ids(self): start, elist = csr(self._n, self.edges) now_ord, group_num = 0, 0 visited = [] low = [0] * self._n ord_ = [-1] * self._n ids = [0] * self._n def dfs(v): nonlocal now_ord, group_num, visited, low, ord_, ids low[v] = ord_[v] = now_ord now_ord += 1 visited.append(v) for i in range(start[v], start[v+1]): to = elist[i] if ord_[to] == -1: dfs(to) low[v] = min(low[v], low[to]) else: low[v] = min(low[v], ord_[to]) if low[v] == ord_[v]: while True: u = visited.pop() ord_[u] = self._n ids[u] = group_num if u == v: break group_num += 1 for i in range(self._n): if ord_[i] == -1: dfs(i) for i in range(self._n): ids[i] = group_num - 1 - ids[i] return group_num, ids def scc(self): group_num, ids = self.scc_ids() groups = [[] for _ in range(group_num)] for i in range(self._n): groups[ids[i]].append(i) return groups class SCC_graph: def __init__(self, n): self._n = n self._scc_graph = _SCC_graph(n) def add_edge(self, frm, to): assert 0 <= frm < self._n assert 0 <= to < self._n self._scc_graph.add_edge(frm, to) def scc(self): return self._scc_graph.scc() N=int(input()) scc_graph = SCC_graph(N) from collections import defaultdict class UnionFind(): def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x def size(self, x): return -self.parents[self.find(x)] def same(self, x, y): return self.find(x) == self.find(y) def members(self, x): root = self.find(x) return [i for i in range(self.n) if self.find(i) == root] def roots(self): return [i for i, x in enumerate(self.parents) if x < 0] def group_count(self): return len(self.roots()) def all_group_members(self): group_members = defaultdict(list) for member in range(self.n): group_members[self.find(member)].append(member) return group_members def __str__(self): return '\n'.join(f'{r}: {m}' for r, m in self.all_group_members().items()) #https://note.nkmk.me/python-union-find/ UF=UnionFind(N) ANS=[] for i in range(N): A=list(map(int,input().split())) ANS.append(A) for j in range(1,len(A)): scc_graph.add_edge(i,A[j]-1) UF.union(i,A[j]-1) groups = scc_graph.scc() members=[-1]*(N) for i in range(len(groups)): for j in range(len(groups[i])): members[groups[i][j]]=i path=defaultdict(list) check=set() for i in range(N): for j in range(1,len(ANS[i])): if members[i]==members[ANS[i][j]-1]: continue if (members[i],members[ANS[i][j]-1]) not in check: check.add((members[i],members[ANS[i][j]-1])) path[members[i]].append(members[ANS[i][j]-1]) check=set() ans=["No"] #print(path) #print(members) def dfs(i,cnt): check.add(i) if len(groups)==cnt or ans[0]=="Yes": ans[0]="Yes" else: #print(path[i]) for j in path[i]: if j not in check: #print(j,cnt) dfs(j,cnt+1) check.discard(i) sys.setrecursionlimit(500000) dfs(members[0],1) print(ans[0])