結果
問題 |
No.778 クリスマスツリー
|
ユーザー |
|
提出日時 | 2025-05-22 18:15:09 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 140 ms / 2,000 ms |
コード長 | 1,199 bytes |
コンパイル時間 | 6,854 ms |
コンパイル使用メモリ | 333,752 KB |
実行使用メモリ | 31,880 KB |
最終ジャッジ日時 | 2025-05-22 18:15:19 |
合計ジャッジ時間 | 8,706 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 12 |
ソースコード
#include <bits/stdc++.h> #include <atcoder/all> using namespace std; using namespace atcoder; using mint = modint998244353; //using mint = modint1000000007; typedef long long ll; typedef pair<ll, ll> P; typedef tuple<ll, ll, ll> T; template<typename T>bool chmax(T& a, const T& b) { if (a < b) { a = b;return true; } else { return false; } } template<typename T>bool chmin(T& a, const T& b) { if (a > b) { a = b;return true; } else { return false; } } const int di[] = { -1,0,1,0 }; const int dj[] = { 0,-1,0,1 }; const long long INF = 9223372036854775807; const int inf = 1001001001; int op(int a, int b) { return a + b; } int e() { return 0; } int main(void) { int n; cin >> n; vector<vector<int>> g(n); for (int i = 0; i < n - 1; i++) { int a; cin >> a; g[a].push_back(i + 1); } segtree<int, op, e> seg(n); ll ans = 0; auto dfs = [&](auto dfs, int pos)->void { //cout << pos << "\n"; ans += seg.prod(0, pos); seg.set(pos, 1); for (auto x : g[pos]) { dfs(dfs, x); //seg.set(x, 0); } seg.set(pos, 0); }; dfs(dfs, 0); cout << ans << "\n"; } //overflow,out_of_range