some times ago i learned LCA and now i am looking for some problems which are solved by the idea to find lca by segment tree to absorb the idea better.does anybody have a suggestion??if you wanna read more about this idea you can read the LCA article in topcoder.
LCA Problems
This problem only asks for LCA link
thank you for your help but i've solved it and some other LCA problems before but now i am looking for some problems which include a higher idea and of course harder algorithms, finding LCA by SEGMENT TREE not the one's which can be solved by the usual LCA idea. if you wanna read more about this idea you can read the LCA article in topcoder.
Bruteforce for LCA got TLE with me in this problem maybe because big number of test cases
Anyway you can test whatever algorithm you want even the constraints are low
if you learn Dynamic Trees you will can solve this problem, LCA in a dynamic tree with operations like Link or Cut.
thank you very much,i've seen some problems like this before but i didn't have any idea how to solve it.and now looks like i've found a new way to think about them.
http://acm.timus.ru/problem.aspx?space=1&num=1699
From Codeforces: this and this.
I think you dont need LCA in 191C(first link) I solved it without LCA and I don't know to solve it with LCA.
Can you please explain how to solve it without LCA? to solve it using LCA we have to make it rooted tree, let's vertex 0 is a root. For each x and y find z = LCA(x, y) Add(0, z, -2) Add(z, x, 1) Add(z, y, 1). Add( a, b, value) — Add value to all edges on the path from a to b. All queries Add we can perform offline using only one DFS.