結果

問題 No.778 クリスマスツリー
ユーザー cielciel
提出日時 2019-01-03 02:38:23
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 514 bytes
コンパイル時間 1,045 ms
コンパイル使用メモリ 68,908 KB
実行使用メモリ 55,168 KB
最終ジャッジ日時 2024-05-02 02:14:54
合計ジャッジ時間 5,813 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

vector<vector<int> >v;
long long dfs(int cur,deque<int> &a){
	long long r=0;
	auto it=lower_bound(a.begin(),a.end(),cur);
	r=distance(a.begin(),it);
	auto it2=a.insert(it,cur);
	for(auto &e:v[cur])r+=dfs(e,a);
	a.erase(it2);
	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);
	deque<int>a;
	printf("%lld\n",dfs(0,a));
}
0