# | User | Rating |
---|---|---|
1 | jiangly | 3640 |
2 | Benq | 3593 |
3 | tourist | 3572 |
4 | orzdevinwang | 3561 |
5 | cnnfls_csy | 3539 |
6 | ecnerwala | 3534 |
7 | Radewoosh | 3532 |
8 | gyh20 | 3447 |
9 | Rebelz | 3409 |
10 | Geothermal | 3408 |
# | User | Contrib. |
---|---|---|
1 | maomao90 | 173 |
2 | adamant | 164 |
3 | awoo | 161 |
4 | TheScrasse | 160 |
5 | nor | 159 |
6 | maroonrk | 156 |
7 | SecondThread | 152 |
8 | pajenegod | 146 |
9 | BledDest | 144 |
10 | Um_nik | 143 |
Name |
---|
Your HLD looks wrong. You have
and later
So if the
adj[v][0] = p
for every node, the complexity blows up. Adding the following code fixes it:You implemented it slightly differently in the other submission, so it doesn't have the same problem, but it still looks a bit wrong. The
tot
variable indfs_tot
looks like is supposed to be the size of the subtree, but then you dotot = cr;
which makes no sense.But I have also done ~~~~~ if(u == p) continue; ~~~~~
So, If any node has atleast 1 child and
adj[v][0] = p
, then it will surely be swapped with adj[v][1], and then loop continues, and hence adj[v][0] will never be p except for leaves. So, Can you please elaborate more?And Sorry for the confusion, But in the second submission I used a different idea for forming the heavy paths, which is I am using length of heavy path down the node instead of subtree size of that node.
Thank you very much, I used what you told and it worked.
Ignore my above comment understand the mistake now. Again thank you!!!
Auto comment: topic has been updated by shashankagrawal (previous revision, new revision, compare).