#include "bits/stdc++.h"
using namespace std;
struct node{
int w;
int to[2200];
int tonum;
int din;
} cam[2200];
int n, m, x, to, ans;
bool flag;
//vector <int> g[110];
void dfs(){
for (int i = 1; i <= n; i++){
if (cam[i].din == 0 && cam[i].w != 0){
cam[i].w = 0;
for (int j = 1; j <= cam[i].tonum; j++) cam[cam[i].to[j]].din--;
dfs();
}
}
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n;
for (int i = 1; i <= n; i++){
cin >> x >> m;
cam[x].tonum = m;
cam[x].w = x;
for (int j = 1; j <= m; j++){
cin >> to;
cam[x].to[j] = to;
cam[cam[x].to[j]].din++;
}
}
for (int i = 1; i <= n; i++)
cout << "cam[i].din=" << cam[i].din << endl;
dfs();
for (int i = 1; i <= n; i++){
cout << "cam[i].din=" << cam[i].din << endl;
if (cam[i].w != 0) ans++;
}
if (ans != 0) cout << ans;
else cout << "YES";
return 0;
}
/*
6
98 1 151
100 2 98 120
120 0
151 1 160
160 2 98 100
500 1 120
*/