結果
| 問題 |
No.778 クリスマスツリー
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-07-12 23:52:00 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 108 ms / 2,000 ms |
| コード長 | 541 bytes |
| コンパイル時間 | 3,923 ms |
| コンパイル使用メモリ | 231,200 KB |
| 実行使用メモリ | 30,592 KB |
| 最終ジャッジ日時 | 2024-09-14 12:36:30 |
| 合計ジャッジ時間 | 5,699 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 12 |
ソースコード
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int N;
cin >> N;
vector<vector<int>> G(N);
atcoder::fenwick_tree<int> fw(N);
for(int i = 1; i < N; i++){
int p;
cin >> p;
G[p].emplace_back(i);
}
long ans = 0;
function<void(int)> dfs = [&](int v){
ans += fw.sum(0, v);
fw.add(v, 1);
for(auto &&u : G[v]) dfs(u);
fw.add(v, -1);
};
dfs(0);
cout << ans << '\n';
}