#include #include #include using namespace std; int main() { int N; cin >> N; vector d(N); atcoder::dsu uf(N); atcoder::scc_graph scc(N); for (int i = 0; i < N; i++) { int M; cin >> M; vector A(M); for (int j = 0; j < M; j++) cin >> A[j]; for (int j = 0; j < M; j++) { A[j]--; d[A[j]]++; uf.merge(i, A[j]); scc.add_edge(i, A[j]); } } bool ok1 = true, ok2 = true, ok3 = false; vector s = scc.scc()[0]; for (int i: s) if (i == 0) ok3 = true; for (int i = 1; i < N; i++) { if (d[i] == 0) ok1 = false; if (!uf.same(0, i)) ok2 = false; } if (ok1 && ok2 && ok3) cout << "Yes\n"; else cout << "No\n"; }