#include using namespace std; //* ATCODER #include using namespace atcoder; typedef modint998244353 mint; //*/ /* BOOST MULTIPRECISION #include using namespace boost::multiprecision; //*/ typedef long long ll; #define rep(i, s, n) for (int i = (int)(s); i < (int)(n); i++) #define rrep(i, s, n) for (int i = (int)(n)-1; i >= (int)(s); i--) template bool chmin(T &a, const T &b) { if (a <= b) return false; a = b; return true; } template bool chmax(T &a, const T &b) { if (a >= b) return false; a = b; return true; } template T max(vector &a){ assert(!a.empty()); T ret = a[0]; for (int i=0; i<(int)a.size(); i++) chmax(ret, a[i]); return ret; } template T min(vector &a){ assert(!a.empty()); T ret = a[0]; for (int i=0; i<(int)a.size(); i++) chmin(ret, a[i]); return ret; } template T sum(vector &a){ T ret = 0; for (int i=0; i<(int)a.size(); i++) ret += a[i]; return ret; } int main(){ int n; cin >> n; vector ikeru(n, vector(0)); rep(i,0,n){ int m; cin >> m; rep(j,0,m){ int a; cin >> a; a--; ikeru[i].push_back(a); } } scc_graph scc(n); rep(i,0,n){ for (int j: ikeru[i]){ scc.add_edge(i, j); } } vector> g = scc.scc(); vector taio(n); int piv = 0; for (auto t: g){ for (int i: t){ taio[i] = piv; } piv++; } if (taio[0] != 0){ cout << "No\n"; return 0; } vector> new_ikeru(piv, vector(0)); rep(i,0,n){ for (int j: ikeru[i]){ if (taio[i] == taio[j]) continue; new_ikeru[taio[i]].push_back(taio[j]); } } vector memo(piv); vector seen(piv); auto calc = [&](auto self, int i) -> int { if (seen[i]) return memo[i]; int ret = 0; for (int j: new_ikeru[i]){ ret = max(ret, self(self, j) + 1); } memo[i] = ret; seen[i] = 1; return ret; }; if (calc(calc, 0) == piv - 1) { cout << "Yes\n"; }else{ cout << "No\n"; } }