結果

問題 No.778 クリスマスツリー
ユーザー cielciel
提出日時 2019-01-03 02:13:46
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 450 bytes
コンパイル時間 484 ms
コンパイル使用メモリ 111,744 KB
実行使用メモリ 10,880 KB
最終ジャッジ日時 2024-05-07 18:21:25
合計ジャッジ時間 4,892 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
10,752 KB
testcase_01 AC 2 ms
5,248 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 TLE -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

vector<vector<int> >v;
long long dfs(int cur,vector<int> &a){
	long long r=0;
	for(int i=0;i<cur;i++)r+=a[i]>0;
	a[cur]+=1;
	for(auto &e:v[cur])r+=dfs(e,a);
	a[cur]-=1;
	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);
	vector<int>a(N);
	printf("%lld\n",dfs(0,a));
}
0