結果
| 問題 |
No.1878 union-find の数え上げ
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-10-22 13:30:48 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 22 ms / 2,000 ms |
| コード長 | 628 bytes |
| コンパイル時間 | 1,793 ms |
| コンパイル使用メモリ | 197,800 KB |
| 最終ジャッジ日時 | 2025-02-08 11:11:57 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 13 |
ソースコード
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using ld = long double;
int main(){
cin.tie(0);
ios::sync_with_stdio(0);
int N; cin >> N;
vector<vector<int>> G(N);
rep(i,N-1) {
int p; cin >> p; p--;
G[p].push_back(i + 1);
}
vector<int> depth(N, 0);
function<void(int)> dfs = [&](int v) -> void {
for(int to : G[v]) {
depth[to] = depth[v] + 1;
dfs(to);
}
}; dfs(0);
ll ans = 1;
rep(i,N) if(i) ans = (ans * depth[i]) % 998244353;
cout << ans << endl;
}