結果
問題 | No.778 クリスマスツリー |
ユーザー | りあん |
提出日時 | 2018-12-25 00:44:27 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 607 bytes |
コンパイル時間 | 3,336 ms |
コンパイル使用メモリ | 211,320 KB |
実行使用メモリ | 39,132 KB |
最終ジャッジ日時 | 2023-10-26 03:08:57 |
合計ジャッジ時間 | 6,513 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,348 KB |
testcase_01 | AC | 2 ms
4,348 KB |
testcase_02 | AC | 2 ms
4,348 KB |
testcase_03 | AC | 2 ms
4,348 KB |
testcase_04 | AC | 2 ms
4,348 KB |
testcase_05 | AC | 2 ms
4,348 KB |
testcase_06 | AC | 199 ms
39,132 KB |
testcase_07 | AC | 60 ms
15,100 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; }