What could be the approach to solve the problem POLQUERY on SPOJ?
-
Ok it is clear that the problem is based on Articulation Points and Bridges. But what to do after that? How can I identify if there is a path from vertex say(u to v) if given edge or vertex is removed? One naive approach is to run the DFS on all Queries which could result in TLE. How to solve this thing? Thanks.
-
Answer:
Remove bridges, enumerate connected components. Find biconnected components, calculate articulate points and form a block tree [substitute all non-cut vertices with a single one for a 2-connected component] (http://en.wikipedia.org/wiki/Biconnected_component). For a type 2 query if C is not articulate point the answer is "ne". Otherwise, use lca to check that the dist(A', C') + dist(C', B') = dist(A', B') [that is that C' lies on the path from A' to B', where A',B',C' is vertices from block tree that correspond A, B, C]. For a type 1 query if (G1, G2) is not a bridge then the answer is ne. Then use same block tree with lca over it to check that dist(A', G1') + dist(B', G2') + 1 = dist(A', B') or dist(A', G2') + dist(B', G1') + 1 = dist(A', B') [edge (G1', G2') lies on the path between vertices A' and B']. Since (G1, G2) is bridge, then (G1', G2') will be an edge (not a loop) in block tree. Side note: there may be a simpler idea based on some clever offline processing or all-in-one dfs.
Roman Iedemskyi at Quora Visit the source
Other answers
This is a very interesting problem.You donât need block cut tree, only a clever solution based on clever offline processing and a dfs to solve this problem.Easy to understand if you understand bridges.Here is an easy to understand and short solution on Github.https://github.com/yancouto/maratona-sua-mae/blob/master/Yan/spoj/polquery.cpp
Anonymous
Related Q & A:
- How to solve such an optimization problem efficiently??Best solution by Theoretical Computer Science
- What's the quickest way to solve a Rubik's Cube?Best solution by Yahoo! Answers
- How do I solve the problem of downloading word document attached to my email?Best solution by support.google.com
- How to solve a random yellow-printing problem?Best solution by lexmark.com
- What is the best approach for me to get a job?Best solution by techrepublic.com
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.