結果

問題 No.778 クリスマスツリー
ユーザー cielciel
提出日時 2019-01-03 03:17:49
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 500 bytes
コンパイル時間 676 ms
コンパイル使用メモリ 61,184 KB
実行使用メモリ 34,080 KB
最終ジャッジ日時 2024-05-02 03:26:47
合計ジャッジ時間 4,213 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
10,624 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 TLE -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize("O3")
#include <vector>
#include <deque>
#include <algorithm>
#include <cstdio>
using namespace std;

vector<vector<int> >v;
vector<int> a;
long long dfs(int cur){
	auto it=lower_bound(a.begin(),a.end(),cur);
	int k=distance(a.begin(),it);
	long long r=k;
	a.insert(it,cur);
	for(auto &e:v[cur])r+=dfs(e);
	a.erase(a.begin()+k);
	return r;
}

int main(){
	int N,x;
	scanf("%d",&N);
	v.resize(N);
	for(int i=1;i<N;i++)scanf("%d",&x),v[x].push_back(i);
	printf("%lld\n",dfs(0));
}
0