Hello everyone. Recently I tried to learn LCA from the topcoder tutorial. I have solved 1 problem (spoj.com/problems/QTREE2) and now I am looking for some other beginers problems. Do you have any suggestions?
| # | User | Rating |
|---|---|---|
| 1 | Kevin114514 | 3722 |
| 2 | Benq | 3676 |
| 3 | jiangly | 3640 |
| 4 | turmax | 3450 |
| 5 | tourist | 3408 |
| 6 | strapple | 3360 |
| 7 | Um_nik | 3354 |
| 8 | squareOf105 | 3348 |
| 9 | maroonrk | 3196 |
| 10 | idontwannadothis…e | 3191 |
| # | User | Contrib. |
|---|---|---|
| 1 | maroonrk | 153 |
| 2 | Qingyu | 152 |
| 3 | nik_exists | 151 |
| 4 | AmShZ | 147 |
| 4 | maspy | 147 |
| 6 | Um_nik | 144 |
| 7 | Errichto | 139 |
| 8 | adamant | 135 |
| 9 | BledDest | 134 |
| 10 | AksLolCoding | 132 |
Hello everyone. Recently I tried to learn LCA from the topcoder tutorial. I have solved 1 problem (spoj.com/problems/QTREE2) and now I am looking for some other beginers problems. Do you have any suggestions?
| Name |
|---|



http://acm.timus.ru/problem.aspx?space=1&num=1471 -- analog of spoj problem
http://acm.timus.ru/problem.aspx?space=1&num=1752 -- more difficult
Also http://acm.timus.ru/problem.aspx?space=1&num=1699
I have been thinking abt 1752 and came up with an idea. And Im interested in if it is correct:
1) using memoization and several sophisticated DFS I will determine for every (u,v) edge ((v,u) being different) longest vertex from u going through v, thereby easily calculating longest vertex from u. hope it is O(N).
2) Then I will make parents array: DP[i][j] = 2^j-th parent from i. (N*Log(N))
3) for every query, determine LCA in (logN) and if d>max(distance(u, LCA(u, longest_from_u)),distance(u, LCA(u, longest_from_u))) then gradually decrease distance between u and LCA(u, longest_from_u) until we reach wanted vertex. else Well if all above is correct there is not really a need to write any more :D.
is it correct? : ))
is there better solution?
Great spoiler is here
I have a confusion about step 1.The longest distance from any to any other node may change when you change the root.think about a complete binary tree with 7 nodes considering 1 as root ((1),(2,3),(4,5,6,7)). the longest distance from any node found by dfs(1) call will return you at most 2 . But if you start dfs from a leaf node does everything remain same??? no, the other leafs are now at distance 4. Am I right?
I didnt understand what you said cuz Im stoned right now. But i can tell I solved using the spoiler mentioned by dalex.
http://codeforces.me/problemset/problem/192/E
this is just LCA problem LCA
Here are some more http://www.lightoj.com/volume_problemcategory.php?category=Range%20Minimum%20Query/Lowest%20Common%20Ancestor
(Need to register first)
Oh yes, completely forgot about lightoj.. Thank you :)
https://www.spoj.com/problems/LCA/ this problem is based only on lca.