結果
問題 | No.778 クリスマスツリー |
ユーザー |
![]() |
提出日時 | 2018-12-25 00:44:27 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 607 bytes |
コンパイル時間 | 2,077 ms |
コンパイル使用メモリ | 210,564 KB |
実行使用メモリ | 39,144 KB |
最終ジャッジ日時 | 2024-09-25 11:07:09 |
合計ジャッジ時間 | 6,023 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
13,756 KB |
testcase_01 | AC | 2 ms
6,940 KB |
testcase_02 | AC | 2 ms
6,940 KB |
testcase_03 | AC | 2 ms
6,940 KB |
testcase_04 | AC | 1 ms
6,940 KB |
testcase_05 | AC | 2 ms
6,944 KB |
testcase_06 | AC | 200 ms
39,144 KB |
testcase_07 | AC | 60 ms
14,876 KB |
testcase_08 | TLE | - |
testcase_09 | -- | - |
testcase_10 | -- | - |
testcase_11 | -- | - |
testcase_12 | -- | - |
testcase_13 | -- | - |
testcase_14 | -- | - |
ソースコード
#include<bits/stdc++.h> using namespace std; const int M = 1000000007; vector<vector<int>> edge; set<int> se; long long dfs(int p, int par) { long long ret = distance(se.begin(), se.lower_bound(p)); se.insert(p); for (auto& i : edge[p]) { if (i == par) continue; ret += dfs(i, p); } se.erase(p); return ret; } int main() { int n; cin >> n; edge = vector<vector<int>>(n); for (int i = 1; i < n; ++i) { int a; cin >> a; edge[i].push_back(a); edge[a].push_back(i); } cout << dfs(0, -1) << "\n"; return 0; }