Page 1 of 1
11354 - Bond
Posted: Sun Nov 25, 2007 11:02 am
by sclo
Looking at the problem, I think the solution can be found by kruskal's algorithm. The problem is how to answer the queries fast enough? In the worst case, the tree can be linear, each query takes O(n) time.
I've not coded it yet.
Posted: Sun Nov 25, 2007 11:57 am
by jah
Hi, I've have not coded it yet but what I thought was the following.
First compute the min spanning tree.
Apply an algorithm similar to LCA to the tree as in problem QTREE of
http://www.spoj.pl. (
http://www.spoj.pl/problems/QTREE/)
Posted: Sun Nov 25, 2007 12:24 pm
by sclo
I think that works, but I haven't solved that problem yet.
Posted: Sun Nov 25, 2007 12:32 pm
by Adrian Kuegel
If you use union by rank, you can answer queries in O(log n) on the union find tree.
Posted: Sun Nov 25, 2007 1:17 pm
by shanto86
can you please describe it a bit more?
Posted: Mon Nov 26, 2007 12:26 am
by sclo
I would like to know how the query can be answered directly on the union find datastructure. I solved it by using the dividing the tree into sqrt(height) layers, and precompute the maximum edge weight to previous layer.
Posted: Mon Nov 26, 2007 8:54 am
by Lomir
Code: Select all
I would like to know how the query can be answered directly on the union find datastructure.
It is interesting to me too.
I solved it just using LCA and calculated maximum edge cost from each vertex by 2^j vertices up.
Then each querry also can be answered in O(log n). Answer is the maximum value from LCA to vertex1 or from LCA to vertex 2.
Posted: Mon Nov 26, 2007 9:32 am
by rio
When constructing the union-find tree, add weight info to the edge in the union-find tree.
For query(a,b):
Code: Select all
query(a,b) := max(the last edge weight of path a -> LCA(a,b),
the last edge weight of path b -> LCA(a,b));
LCA(a,b) is LCA of a,b in union-find tree.
The hight of tree is O(logn), so you could answer the query with O(logn).
-----
Rio
Re: 11354 - Bond
Posted: Fri Apr 11, 2008 3:13 pm
by davidsun
I really want to know what your algorithm is. I know I can use a segment tree or something like this, but I really don't know HOW to use it.
I'm interested in your O(log N) solution, so can you explain it more carefully, or do you have any lecture about it?
Re: 11354 - Bond
Posted: Sat Apr 19, 2008 4:14 pm
by rio
davidsun wrote:I really want to know what your algorithm is. I know I can use a segment tree or something like this, but I really don't know HOW to use it.
I'm interested in your O(log N) solution, so can you explain it more carefully, or do you have any lecture about it?
Union-find tree is different from segment tree.
Heres a pdf about union-find tree I found on web:
http://valis.cs.uiuc.edu/~sariel/teach/ ... /22_uf.pdf
Once you understand about this data structure, I think you could understand the algorithm I said.
-----
Rio
Re: 11354 - Bond
Posted: Sun Dec 07, 2008 7:25 am
by empo
Can anyone tell me the algo for LCA...i am not getting it...
Re: 11354 - Bond
Posted: Fri Feb 27, 2009 12:39 pm
by Jan
Re: 11354 - Bond
Posted: Fri Mar 29, 2013 11:03 pm
by aman181993
(
http://www.spoj.pl/problems/QTREE/)
can some1 please explain the updation part in this problem using LCA
Re:
Posted: Mon Dec 23, 2013 10:27 pm
by csprajeeth
rio wrote:When constructing the union-find tree, add weight info to the edge in the union-find tree.
For query(a,b):
Code: Select all
query(a,b) := max(the last edge weight of path a -> LCA(a,b),
the last edge weight of path b -> LCA(a,b));
LCA(a,b) is LCA of a,b in union-find tree.
The hight of tree is O(logn), so you could answer the query with O(logn).
-----
Rio
Brilliant. I never thought of that. I constructed a new tree and answered LCA(u,v) using heavy-light decomposition technique... Got me the last rank... and then used ur idea... rank 19.

thanks