結果
| 問題 |
No.778 クリスマスツリー
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2018-12-26 16:12:28 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
MLE
|
| 実行時間 | - |
| コード長 | 1,000 bytes |
| コンパイル時間 | 633 ms |
| コンパイル使用メモリ | 64,136 KB |
| 実行使用メモリ | 814,388 KB |
| 最終ジャッジ日時 | 2024-10-01 14:43:42 |
| 合計ジャッジ時間 | 2,975 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 3 MLE * 1 -- * 8 |
ソースコード
#include <iostream>
#include <vector>
#include <list>
using namespace std;
struct Node {
Node(){
count=0;
finished=false;
}
int i;
int parent;
int count;
bool finished;
};
void count(vector<Node> &nodes,Node &node,list<Node*> path)
{
if(node.parent>=0)
{
Node &parent = nodes[node.parent];
path.push_back(&node);
count(nodes,parent,path);
path.pop_back();
node.finished=true;
}
for( Node *child: path){
if(!child->finished && child->i > node.i){
// cout << child->i << ":" << node.i << endl;
child->count++;
}
}
}
int main() {
int N;
cin >> N;
vector<Node> nodes(N);
nodes[0].i=0;
nodes[0].parent=-1;
for(int i=1;i<nodes.size();i++){
int parent;
cin >> parent;
nodes[i].i = i;
nodes[i].parent = parent;
}
list<Node*> path;
for(int i=1;i<nodes.size();i++){
Node &node = nodes[i];
count(nodes,node,path);
}
int ans = 0;
for(int i=0;i<nodes.size();i++){
ans += nodes[i].count;
}
cout << ans;
// your code goes here
return 0;
}