結果
| 問題 |
No.778 クリスマスツリー
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-01-03 03:17:49 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 500 bytes |
| コンパイル時間 | 670 ms |
| コンパイル使用メモリ | 66,800 KB |
| 最終ジャッジ日時 | 2025-01-06 20:08:19 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 11 TLE * 1 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:22:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
22 | scanf("%d",&N);
| ~~~~~^~~~~~~~~
main.cpp:24:34: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
24 | 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;
vector<int> a;
long long dfs(int cur){
auto it=lower_bound(a.begin(),a.end(),cur);
int k=distance(a.begin(),it);
long long 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("%lld\n",dfs(0));
}