Did not actually written before this type of questions, questions are not read-site ,, cried
Meaning of the questions: There are n children, each child has a k [i] pieces you want, now randomly pick a child, he wanted a gift from which a randomly selected, and then sent to another child, and asked you to send this gift probability after a child's wish list in
Suppose we now pick out a child x, he singled out the probability is 1 / n, choose a gift from his wish list, the probability becomes 1 / n * 1 / k [x], then pick a child and in line with the probability: 1 / n * 1 / k [x] * cnt [the gift] / n;
#define mod 998244353
///快速幂m^k%mod
ll qpow(int m, int k)
{
ll res=1, t=m;
while (k)
{
if(k&1) res = res * t % mod;
t = t * t % mod;
k >>= 1;
}
return res;
}
// 快速幂求逆元
int Fermat(int a,int p)//费马求a关于b的逆元
{
return qpow(a,p-2);
}
int cnt[MAXN],k[MAXN];
vector<int>a[MAXN];
int main()
{
fast;
int n;cin>>n;
rep(i,n)
{
cin>>k[i];
a[i].resize(k[i]);
rep(j,k[i]) cin>>a[i][j],++cnt[a[i][j]];//记录想要该礼物的人数
}
ll ans=0;
rep(i,n)
{
ll cur=0;
rep(j,k[i]) cur+=cnt[a[i][j]];
ans+=((cur%mod)*Fermat(k[i],mod))%mod;
}
ans=((ans%mod)*Fermat((1ll*n*n)%mod,mod))%mod;
cout<<ans<<endl;
//stop;
return 0;
}