結果

問題 No.778 クリスマスツリー
ユーザー cielciel
提出日時 2019-01-03 03:19:24
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 458 bytes
コンパイル時間 818 ms
コンパイル使用メモリ 66,972 KB
実行使用メモリ 64,656 KB
最終ジャッジ日時 2024-05-02 03:32:48
合計ジャッジ時間 3,809 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 105 ms
64,656 KB
testcase_07 AC 29 ms
8,732 KB
testcase_08 WA -
testcase_09 AC 111 ms
10,844 KB
testcase_10 AC 112 ms
10,788 KB
testcase_11 AC 106 ms
10,876 KB
testcase_12 AC 85 ms
10,720 KB
testcase_13 AC 45 ms
10,736 KB
testcase_14 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <vector>
#include <deque>
#include <algorithm>
#include <cstdio>
using namespace std;

vector<vector<int> >v;
deque<int> a;
int dfs(int cur){
	auto it=lower_bound(a.begin(),a.end(),cur);
	int k=distance(a.begin(),it);
	int 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("%d\n",dfs(0));
}
0