先选一个人,再从这个人中选一个礼物,再随机选一个人,求选的这个礼物恰好是这个人想要的概率
int mod = 998244353;
int p[MAXN];
vector<int> vec[MAXN];
ll powmod(ll a,ll b,ll p) {
ll res = 1;
while(b) {
if(b&1) res = res*a%p;
a = a*a%p;
b >>= 1;
}
return res;
}
ll getp(ll x, ll y) {
return x*powmod(y,mod-2,mod)%mod;
}
int main() {
love;
int n,k,x;
cin >> n;
for(int i = 1; i <= n; i++) {
cin >> k;
for(int j= 1; j <= k; j++) {
cin >> x;
vec[i].push_back(x);
}
}
ll pone = getp(1,n);
for(int i = 1; i <= n; i++) {
int sum = vec[i].size();
for(int j = 0;j < vec[i].size();j++) {
p[vec[i][j]] = (p[vec[i][j]] + pone*getp(1,sum)%mod)%mod;
}
}
ll ans = 0;
for(int i = 1; i <= n; i++) {
for(int j = 0; j < vec[i].size(); j++) {
ans = (ans + pone * p[vec[i][j]] % mod) % mod;
}
}
cout << ans << endl;
system("pause");
return 0;
}