#include #include #include using namespace std; #define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i using mint = atcoder::modint998244353; int main() { cin.tie(nullptr)->sync_with_stdio(false); int N; cin >> N; vector> to_edges(N); vector edgexor(N - 1); REP(i, N) { int C; cin >> C; while (C--) { int e; cin >> e; --e; edgexor.at(e) ^= i; to_edges.at(i).push_back(e); } } vector dpchild(N), dppar(N); vector ret(N); vector curs(N, -1); auto rec1 = [&](auto &&self, int now, int prvvid, int prveid) -> void { if (prveid >= 0) { int cur = 0; while (to_edges.at(now).at(cur) != prveid) ++cur; curs.at(now) = cur; } const int D = to_edges.at(now).size(); for (int eid : to_edges.at(now)) { if (eid != prveid) self(self, edgexor.at(eid) ^ now, now, eid); } vector tmp; tmp.reserve((1 + D) * 2); tmp.push_back(1); for (int eid : to_edges.at(now)) tmp.push_back(dpchild.at(edgexor.at(eid) ^ now)); REP(i, 1 + D) tmp.push_back(tmp.at(i)); vector tmp_cs(tmp.size() + 1); const mint w = mint(now + 1).inv(); const mint winvpow = mint(now + 1).pow(D); REP(i, tmp.size()) tmp_cs.at(i + 1) = tmp_cs.at(i) * w + tmp.at(i); auto get_sum = [&](int l) -> mint { return tmp_cs.at(l + D) * winvpow - tmp_cs.at(l); }; ret.at(now) += get_sum(1); if (curs.at(now) >= 0) dpchild.at(now) += get_sum(1 + curs.at(now) + 1); REP(d, D) { int nxt = edgexor.at(to_edges.at(now).at(d)) ^ now; if (nxt != prvvid) dppar.at(nxt) += get_sum(1 + d + 1); } }; rec1(rec1, 0, -1, -1); auto rec2 = [&](auto &&self, int now, int prveid) -> void { const int D = to_edges.at(now).size(); ret.at(now) += dppar.at(now) * mint(now + 1).pow(1 + curs.at(now)); REP(d, D) { const int eid = to_edges.at(now).at(d); if (eid == prveid) continue; int nxt = edgexor.at(eid) ^ now; if (prveid >= 0) { dppar.at(nxt) += dppar.at(now) * mint(now + 1).pow((curs.at(now) + (D + 1) - d) % (D + 1)); } self(self, nxt, eid); } }; rec2(rec2, 0, -1); for (auto x : ret) cout << x.val() << '\n'; }