結果

問題 No.778 クリスマスツリー
ユーザー cielciel
提出日時 2019-01-04 02:25:40
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 262 ms / 2,000 ms
コード長 680 bytes
コンパイル時間 2,422 ms
コンパイル使用メモリ 142,276 KB
実行使用メモリ 36,316 KB
最終ジャッジ日時 2024-04-22 03:07:16
合計ジャッジ時間 4,386 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 194 ms
36,096 KB
testcase_07 AC 33 ms
9,248 KB
testcase_08 AC 262 ms
22,020 KB
testcase_09 AC 116 ms
11,220 KB
testcase_10 AC 104 ms
11,248 KB
testcase_11 AC 117 ms
11,392 KB
testcase_12 AC 100 ms
11,256 KB
testcase_13 AC 54 ms
11,264 KB
testcase_14 AC 194 ms
36,316 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/tag_and_trait.hpp>
template<typename K>
using tree = __gnu_pbds::tree<K,__gnu_pbds::null_type,std::less<K>,__gnu_pbds::rb_tree_tag,__gnu_pbds::tree_order_statistics_node_update>;

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

vector<vector<int> >v;
tree<int>a;
long long dfs(int cur){
	int k=a.order_of_key(cur);
	long long r=k;
	a.insert(cur);
	for(auto &e:v[cur])r+=dfs(e);
	a.erase(a.find(cur));
	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