結果
問題 |
No.778 クリスマスツリー
|
ユーザー |
|
提出日時 | 2019-01-03 02:46:21 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 468 bytes |
コンパイル時間 | 790 ms |
コンパイル使用メモリ | 65,792 KB |
実行使用メモリ | 64,640 KB |
最終ジャッジ日時 | 2024-11-22 12:07:42 |
合計ジャッジ時間 | 5,681 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 5 RE * 7 |
ソースコード
#include <vector> #include <deque> #include <algorithm> #include <cstdio> using namespace std; vector<vector<int> >v; deque<int> a; long long dfs(int cur){ 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.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); printf("%lld\n",dfs(0)); }