#include <bits/stdc++.h> using namespace std; class SCC{ public: int siz = 0,name = 0,nowc = 0; vector<bool> already; vector<int> ord,low,belong,topo; vector<vector<int>> Graph,cycle; stack<int> St; void dfs(int pos){ low.at(pos) = (ord.at(pos) = name++); St.push(pos); for(auto to : Graph.at(pos)){ if(ord.at(to) == -1){ dfs(to); low.at(pos) = min(low.at(pos),low.at(to)); } else if(!already.at(to)) low.at(pos) = min(low.at(pos),ord.at(to)); } if(low.at(pos) == ord.at(pos)){ cycle.push_back({}); while(true){ int s = St.top(); St.pop(); cycle.back().push_back(s); belong.at(s) = nowc; already.at(s) = true; if(s == pos) break; } nowc++; } } void make(vector<vector<int>> &G){ Graph = G; siz = G.size(); ord.resize(siz,-1); low.resize(siz,1001001001); already.resize(siz); belong.resize(siz); for(int i=0; i<siz; i++) if(ord.at(i) == -1) dfs(i); for(int i=0; i<siz; i++) belong.at(i) = (nowc-1)-belong.at(i); reverse(cycle.begin(),cycle.end()); } }; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int N; cin >> N; vector<vector<int>> Graph(N); for(int i=0; i<N; i++){ int K; cin >> K; for(int k=0; k<K; k++){ int to; cin >> to; to--; Graph.at(i).push_back(to); } } SCC Z; Z.make(Graph); if(Z.belong.at(0) != 0){cout << "No" << endl; return 0;} reverse(Z.cycle.begin(),Z.cycle.end()); set<int> S; bool end = true; for(auto &Vs : Z.cycle){ set<int> S2; for(auto pos : Vs) S2.insert(pos); if(end){end = false; S = S2; continue;} bool ok = false; for(auto pos : Vs){ for(auto to : Graph.at(pos)) if(S.count(to)){ok = true; break;} if(ok) break; } if(!ok){cout << "No" << endl; return 0;} S = S2; continue; } cout << "Yes" << endl; }