#include #include #include using namespace std; struct Node { Node(){ count=0; } int i; int parent; int count; }; void count(vector &nodes,Node &node,list path) { if(node.parent>=0) { Node &parent = nodes[node.parent]; path.push_back(&node); count(nodes,parent,path); path.pop_back(); } for( Node *child: path){ if(child->i > node.i){ child->count++; } } } int main() { int N; cin >> N; vector nodes(N); nodes[0].i=0; nodes[0].parent=-1; for(int i=1;i> parent; nodes[i].i = i; nodes[i].parent = parent; } list path; for(int i=1;i