#include #include #include #include #include using mint = atcoder::modint998244353; std::vector naive(int n, const std::vector>& edges) { std::vector> g(n); for (const auto& [u, v] : edges) { g[u].push_back(v); g[v].push_back(u); } std::vector f(n, 1); for (int x = 0; x < n; ++x) { std::vector vis(n); vis[x] = true; std::deque dq{ x }; while (dq.size()) { int u = dq.front(); dq.pop_front(); for (int v : g[u]) if (not vis[v]) { vis[v] = true; if (v < x) { dq.push_back(v); } if (v > x) { f[v] += f[x]; } } } } return f; } #include #include #include std::vector solve(int n, const std::vector>& edges) { atcoder::dsu uf(n); std::vector> ts(n); for (const auto& [u, v] : edges) { ts[u].push_back(v); } std::vector> neighbors(n); std::vector lazy(n); for (const auto& [u, v] : edges) { neighbors[v].insert(u); } std::vector f(n, 1); for (int s = 0; s < n; ++s) { std::vector cmps; for (int t : ts[s]) { cmps.push_back(uf.leader(t)); } std::sort(cmps.begin(), cmps.end()); cmps.erase(std::unique(cmps.begin(), cmps.end()), cmps.end()); for (int t : cmps) { uf.merge(s, t); f[s] += lazy[t]; lazy[s] += lazy[t]; } lazy[s] += f[s]; if (cmps.empty()) continue; auto argmax = *std::max_element(cmps.begin(), cmps.end(), [&](int i, int j) { return neighbors[i].size() < neighbors[j].size(); }); for (int t : cmps) if (t != argmax) { lazy[s] -= lazy[t]; } for (int t : cmps) if (t != argmax) { for (int neighbor : neighbors[t]) if (neighbor != s) { f[neighbor] += lazy[t]; if (neighbors[argmax].count(neighbor)) { continue; } f[neighbor] -= lazy[argmax]; neighbors[argmax].insert(neighbor); } } if (s != argmax) { for (int neighbor : neighbors[s]) if (neighbor != s) { if (neighbors[argmax].count(neighbor)) { continue; } f[neighbor] -= lazy[argmax]; neighbors[argmax].insert(neighbor); } } int root = uf.leader(s); std::swap(lazy[root], lazy[s]); std::swap(neighbors[root], neighbors[argmax]); neighbors[root].erase(s); } return f; } int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); int n, m; std::cin >> n >> m; std::vector> edges(m); for (auto& [u, v] : edges) { std::cin >> u >> v; --u, --v; if (u < v) { std::swap(u, v); } } bool debug = false; if (debug) { auto f = naive(n, edges); for (const auto& e : f) { std::cout << e.val() << std::endl; } auto g = solve(n, edges); for (const auto& e : g) { std::cout << e.val() << std::endl; } } else { mint ans = 0; for (const auto &e : solve(n, edges)) ans += e; std::cout << ans.val() << std::endl; } }