結果
| 問題 |
No.778 クリスマスツリー
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-01-03 02:38:23 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 514 bytes |
| コンパイル時間 | 896 ms |
| コンパイル使用メモリ | 73,904 KB |
| 最終ジャッジ日時 | 2025-01-06 20:07:47 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 5 RE * 7 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:21:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
21 | scanf("%d",&N);
| ~~~~~^~~~~~~~~
main.cpp:23:34: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
23 | for(int i=1;i<N;i++)scanf("%d",&x),v[x].push_back(i);
| ~~~~~^~~~~~~~~
ソースコード
#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));
}