Comments

thanks.

unordered_map made me win the battle but lose the war for C.

oh Sorry, right. Thanks.

3 is only the correct solution right?

For D, why does doing dfs, returning the amount of white nodes in the subtree, then accordingly pairing all the white nodes in the different subtrees fail?

int Tree(vector<vector<int>>&adj,int root,int &op){
    if(adj[root].size()==0)return 1;
    priority_queue<int> nodes;
    for(int v:adj[root]){
        nodes.push(Tree(adj,v,op));
    }
    while(nodes.size()>1) {
        int t1 = nodes.top();
        nodes.pop();
        int t2 = nodes.top();
        nodes.pop();
        op +=t2;
        if(t1!=t2)nodes.push(t1-t2);
    }
    return nodes.empty() ? 1 : nodes.top() + 1;
}
int main()
{
    testcases{
        int n;
        cin>>n;
        vector<vector<int>> adj(n+1);
        for(int i=2;i<=n;i++){
            int u;
            cin>>u;
            adj[u].push_back(i);
        }
        int op = 0;
        Tree(adj,1,op);
        cout<<op<<endl;
    }
 return 0;
}

Thank you

why was this failing but if only I changed (n^(1<<i)) part to (((ll)n)^((ll)(pow(2,i)))) it worked

#include <bits/stdc++.h>
#define ll long long
#define fori(n) for(long long i=0; i<n; i++)
#define fori1(n) for(long long i=1; i<n; i++)
#define forj(n) for(long long j=0; j<n; j++)
#define testcases int t; cin>>t; while (t--)
#define ld long double
#define vl vector<long long>
#define vint vector<int>
#define pb emplace_back
#define fast ios::sync_with_stdio(0); cin.tie(0);
using namespace std;
int main()
{
    testcases{
        ll n;
        cin>>n;
        vector<int> s;
        for(int i=60;i>=0;i--){
            if((n>>i)&1)s.push_back(i);
        }
        if(s.size()==1){
            cout<<1<<endl;
            cout<<n<<endl;
            continue;
        }
        cout<<s.size()+1<<endl;
        for(int i:s){
            cout<<(n^(1<<i))<<" ";
        }
        cout<<n;
        cout<<endl;
    }
 return 0;
}