結果
問題 | No.2980 Planar Tree 2 |
ユーザー |
|
提出日時 | 2024-12-05 02:16:14 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 157 ms / 2,000 ms |
コード長 | 1,204 bytes |
コンパイル時間 | 3,267 ms |
コンパイル使用メモリ | 285,212 KB |
実行使用メモリ | 33,648 KB |
最終ジャッジ日時 | 2025-06-20 11:24:56 |
合計ジャッジ時間 | 7,182 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 31 |
ソースコード
#include <bits/stdc++.h> #include <atcoder/modint> using ll = long long; using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; struct edge { int to; edge(int _to) : to(_to) {} }; vector<vector<edge>> G(n); for (int i = 0; i < n - 1; ++i) { int a, b; cin >> a >> b; a--, b--; G[a].emplace_back(b); G[b].emplace_back(a); } if (n <= 3) { cout << 1 << endl; return 0; } using mint = atcoder::modint998244353; vector<mint> factorial(n + 1); factorial[0] = 1; for (int i = 1; i <= n; ++i) { factorial[i] = factorial[i - 1] * i; } vector<bool> seen(n); auto dfs = [&](auto dfs, int u) -> mint { seen.at(u) = true; mint res = 1; int cnt = 0; for (const auto &e : G.at(u)) { if (seen.at(e.to)) continue; res *= dfs(dfs, e.to); cnt++; } res *= factorial[cnt + 1]; return res; }; mint num = dfs(dfs, 0) / (G[0].size() + 1); mint den = factorial[n - 1]; cout << (num / den).val() << endl; return 0; }