02:22, i guess at here in special dfs tree, for the current node x, if it is a leaf node, dis(x,x+ 1) would not be 1.. to find x + 1, we can keep going to the parent until we find a parent with sub_max_node[parent] > x.. great explanation man..
Answer to last question: For each edge (i, par[i]) it's contribution will be (subtree(i) * (n - subtree(i))). Do add this much for all edges to answer. Multiply weight of the edge for weighted graph.
I think some variables are not required. unlocked_sum and locked_sum are not required only one variable sum will be sufficient. Below assigned[v]+=w only do sum+=w and remove unblocked_sum and locked_sum from everywhere. At time of events your answer would be ans=sum+unlocked_count*remain Why? Because see brute force you will notice you need sum of all node's assigned[i] value and assigned [i] value is just some of w's. So, the "sum" is doing the same thing. Keep everything else same. Please correct me if i am wrong anywhere. Btw your explanations are too good keep it up.
Great explanation, the amount of effort you put in for the video and the website is commendable!!
Thank you.
Was able to solve the weighted part completey myself after fully understanding contribution technique ....great video man..please keep uploading..
Bro i really liked your approach for problem solving please continue this series , very help full for competitive coders specially for higher ones .
02:22, i guess at here in special dfs tree, for the current node x, if it is a leaf node, dis(x,x+ 1) would not be 1.. to find x + 1, we can keep going to the parent until we find a parent with sub_max_node[parent] > x.. great explanation man..
Helpfull
Thanks. You have some good content on your channel as well. Keep it up!
@@cfstepofficial Thank You
understood 👍🏻♥️
Answer to last question:
For each edge (i, par[i]) it's contribution will be
(subtree(i) * (n - subtree(i))).
Do add this much for all edges to answer. Multiply weight of the edge for weighted graph.
Yep, that's correct.
I think some variables are not required.
unlocked_sum and locked_sum are not required only one variable sum will be sufficient.
Below assigned[v]+=w only do sum+=w and remove unblocked_sum and locked_sum from everywhere.
At time of events your answer would be ans=sum+unlocked_count*remain
Why?
Because see brute force you will notice you need sum of all node's assigned[i] value and assigned [i] value is just some of w's.
So, the "sum" is doing the same thing. Keep everything else same.
Please correct me if i am wrong anywhere.
Btw your explanations are too good keep it up.
Fair enough.