#include using namespace std; typedef signed long long ll; #define _P(...) (void)printf(__VA_ARGS__) #define FOR(x,to) for(x=0;x<(to);x++) #define FORR(x,arr) for(auto& x:arr) #define FORR2(x,y,arr) for(auto& [x,y]:arr) #define ALL(a) (a.begin()),(a.end()) #define ZERO(a) memset(a,0,sizeof(a)) #define MINUS(a) memset(a,0xff,sizeof(a)) template bool chmax(T &a, const T &b) { if(a bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;} //------------------------------------------------------- int N; int M[101010]; vector A[101010]; int vis[101010]; class SCC { public: static const int MV = 2025000; vector > SC; int NV,GR[MV]; private: vector E[MV], RE[MV], NUM; int vis[MV]; public: void init(int NV) { this->NV=NV; for(int i=0;i=0;i--) if(!vis[NUM[i]]){ SC[c].clear(); revdfs(NUM[i],c); sort(SC[c].begin(),SC[c].end()); c++; } SC.resize(c); } }; SCC scc; void solve() { int i,j,k,l,r,x,y; string s; cin>>N; scc.init(N); FOR(i,N) { cin>>M[i]; FOR(j,M[i]) { cin>>x; A[i].push_back(x-1); scc.add_edge(i,x-1); } } scc.scc(); set S; FOR(i,N) FORR(e,A[i]) if(scc.GR[i]+1==scc.GR[e]) S.insert(scc.GR[i]); if(S.size()+1==scc.SC.size()) { cout<<"Yes"<