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