L_user's blog

By L_user, history, 4 years ago, In English

I've tried everything I could but still didn't understand why my solution is failing. Here, is the link to my solution

https://codeforces.com/contest/734/submission/70750042

Please help. Thank you!

Full text and comments »

  • Vote: I like it
  • 0
  • Vote: I do not like it

By L_user, history, 7 years ago, In English

This is my first blog on codeforces so please don't be rude :)

I'm facing some issues while solving a problem. The problem is you have to find a path between two nodes in an undirected tree. And the approach i came up with is find the lca of node 'A' and 'B' and then print the path from node 'A' to lca and then from the next node after lca to node 'B'.

For example consider the above picture, you can see that node A = 8, node B = 10,
lca(A, B) = 4.

I can find lca(A, B) using sparse table but the problem is how can i find path from node 'A' to lca and the path from node 'B' to lca. I know i can do a dfs for finding the path but thats brute force i need a more efficient solution. What i want to say is that i need an algorithm that will only check path 8->1->2->->4->5 and not 4->7->10 if node A = 8, node B = 9 & lca(A, B) = 5. Can i use dfs ordering? If so then how? Thanks in advance!

Full text and comments »

Tags lca, dfs
  • Vote: I like it
  • +2
  • Vote: I do not like it