結果
| 問題 |
No.2980 Planar Tree 2
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-12-04 00:24:52 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 268 ms / 2,000 ms |
| コード長 | 1,174 bytes |
| コンパイル時間 | 13,148 ms |
| コンパイル使用メモリ | 731,852 KB |
| 実行使用メモリ | 35,220 KB |
| 最終ジャッジ日時 | 2025-06-20 11:22:55 |
| 合計ジャッジ時間 | 17,888 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 31 |
ソースコード
#include <bits/stdc++.h>
#include <atcoder/all>
using mint = atcoder::static_modint<998244353>;
//using mint = atcoder::static_modint<1000000007>;
using namespace std;
using namespace atcoder;
using ld = long double;
using ll = long long;
#define mp(a,b) make_pair(a,b)
#define rep(i,s,n) for(int i=s; i<n; i++)
const vector<int> dx{1,0,-1,0},dy{0,1,0,-1};
vector<vector<int>> G(200000);
vector<int> subsize(200000,1);
vector<mint> factorial(200001,1),invfactorial(200001,1);
mint ans=1;
void dfs(int x,int p){
int c=0;
if(p!=-1)c++;
mint k=1;
for(auto y:G[x])if(y!=p){
c++;
dfs(y,x);
k*=factorial[subsize[y]];
subsize[x]+=subsize[y];
}
k*=factorial[c];
if(p!=-1)k*=invfactorial[subsize[x]];
else k*=invfactorial[subsize[x]-1];
ans*=k;
// cout << x << " " << k.val() << "\n";
}
int main(){
int n;cin >> n;
int u,v;
rep(i,0,n-1){
cin >> u >> v,u--,v--;
G[u].push_back(v);
swap(u,v);
G[u].push_back(v);
}
rep(i,1,200001){
factorial[i]=i*factorial[i-1];
invfactorial[i]=factorial[i].inv();
}
dfs(0,-1);
cout << ans.val();
}