結果
| 問題 |
No.2980 Planar Tree 2
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-12-05 02:14:25 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,188 bytes |
| コンパイル時間 | 3,065 ms |
| コンパイル使用メモリ | 255,392 KB |
| 実行使用メモリ | 33,664 KB |
| 最終ジャッジ日時 | 2024-12-05 02:14:32 |
| 合計ジャッジ時間 | 6,772 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 17 WA * 13 |
ソースコード
#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) / 2;
mint den = factorial[n - 1];
cout << (num / den).val() << endl;
return 0;
}