You are given an undirected connected graph with n nodes and n edges. Now Given two nodes a and b. find the number of edges that lies in path from a to b but are not part of cycle. (as number of edges is n there will be a cycle for sure). Can this be done by dsu data structure because if removing an edge disconnects a and b we can count it in answer. Thanks in advance.
Can this problem done without bfs or storing edges?
57 Views Asked by piyushnbali At
1
There are 1 best solutions below
Related Questions in GRAPH
- Querying Office for National Statistics data using SPARQL
- Which mathematical algorithm is used for interpolation between datapoints in Smooth Line Chart of Echart?
- how can I use coordinates of path walked by multiple subjects
- Creating a Graph/Chart needing TWO secondary axis options for a combination of Clustered and Stacked Graph Columns
- How to stretch specific y axis intervals so the space between some values is larger than between others?
- out of order time points on multi line chart
- What does negative flow on a reverse arc of a graph in Boykov-Kolmogorov max flow algorithm mean?
- how to generate {8,3} regular graphs for large number of vertices
- Why can't I apply ModularityState from graph-tool on a graph in XML format?
- Update Node from OneTBB Library
- Find the smallest set of vertices in a graph such that you can still reach any point in the set when any single vertex is removed
- Graph Neural Network Custom Data
- FIFO-property in graphs
- How to display total count of bars for each group in Google Charts on the right side of the graph or in legend position
- Whats wrong on Graph API permission for selected site
Related Questions in NODES
- What line of code do I change to avoid duplication in a linked list?
- AVL tree Nth largest operation - How to have all my tests pass? JAVA
- Node border width control in Netgraph
- Java Jackson update json 2nd value instance in array
- Nodes of a Sankey diagram in R don't group together
- Change size of terminal_panel = node_barplot in ctree
- Make a Cluster without using MongoDB Atlas
- reactive props in Vue3 Treelist causes recursive updates
- Creating a Method in C# that traverses HTML document and extracts content based on a query, i.e Custom HTML Crawler
- Get status(like/dislike) or colour of node using accessibility service
- Handle replace nodes due to remove or crash at Artifactory
- Drawing a node in click position using Vis.js
- How do I make several nodes line up and move up when the first one is removed? (GDscript)
- Which node should I use to detect mouse or touch drag on screen in Godot
- Why is my element not a node ? Drag and Drop
Related Questions in BREADTH-FIRST-SEARCH
- Leetcode BFS Set insertion giving TLE (200. Number of Islands)
- Why DFS and not BFS for finding cycle in graph
- Approach for solving a Breadth first search(BFS) components problem
- Breadth First Search Causing Heap Memory Error With exponentially growing graph
- Undirected Graph, get list of all nodes that can be visited
- Struggling to separate breadth first search section of my main loop into its own function
- Algorithm to connect every node between each level of a graph / tree
- Generate tuples of non-negative integers closed under promotion?
- Finding goal through BFS and DFS
- Number of islands problem Leetcode recursive DFS and non recursive BFS
- Print path to node in a 2D dictionary-structured graph
- BFS Maximize Minimum Distance from a Monster along a path
- Find the path with the minimum number of transfers between stations?
- BFS ever failing for a unweighted and undirected graph?
- How would I show the parenthesis theorem doesn't work for Breadth First Search?
Related Questions in EDGES
- Color edges according to edge attribute in visNetwork
- edge and nodes labels using "cytoscape-node-html-label"
- Create the edges out of a list of nodes when their levels in the network are known
- How to iterate through list and replace attribute with another list with same attribute Python
- How to get a list of edges in python corresponding to a set?
- How to select subnetworks, or regions, with a certain number of nodes or edges with RCy3
- Given an directed acyclic graph, create a strategy so that there is a bidirectional path between all possible Vertices
- Edge Addition: Item subset selection problem (Knapsack?)
- Save Coordinates Edges OpenCV tuples to txt
- Adding segments to a geom_polygon ggplot
- Networkx - graph & egdes attributes from csv file
- Why can't I add edges to manim graph?
- ArangoDB: Edges inserted in a collection are not shown in the graph
- How do I distinguish between source and target nodes by edges in large graphs?
- Add Edge computing server between the clients and server
Related Questions in DISJOINT-UNION
- disjoint union in julia
- Typescript: Checking disjoint union with extra null-checks
- Disjoint Union of Strings
- How to merge sets in better then O(len(set))?
- Insert items into a list based on their occurrence
- Representatives in Disjoint Set Union
- Getting ambiguous error for Vector. How to Fix it?
- Returning the right number of islands using Union Find
- Disjoint Set Union
- Leetcode Number of Province not passing edge case last few edge case
- Distance to representative in Disjoint set union data structure
- Amortized complexity of the union operation
- How to solve this Union-Find disjoint set problem?
- mother vertex using disjoint dataset in directed graph
- union find set algorithm return parent[v] = find_set(parent[v]); means
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular # Hahtags
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
Of course you can solve the problem through DSU as you mentioned, but the solution is not efficient enough. DSU is not good at deleting edges, so if you want to use DSU to solve the problem, you need to
Even if you implement a DSU with the path compressing and merging by rank technique, the time complexity for one query is O(n^2a(n)), where a(n) is the anti-ackermann function. It's unacceptable.
If you really want to solve the problem by enumerating and deleting edges, link cut tree is recommended which can delete or add an edge in O(logn) time. In this way, you can answer the query in O(nlogn) time.
But there do exist some really efficient algorithms which can answer each query in O(1) time if you do some preprocessing job. The graph is special: a connected graph with n vertices and n edges has only one cycle. We can regard this graph as a cycle with t vertices, each vertex is the root of a tree. So during preprocessing, we use dfs to calculate which tree each vertex is in and the depth of each vertex (in its corresponding tree, the depth of each root is 0). Besides, we use tarjan algorithm to preprocess each tree for the sake of querying LCA in O(1) time.
Then for each query, given two vertex
uandv, we firstly check whether they're in the same tree. There're two situations:uandvand obviously, the shortest distance is depth(u)+depth(v)-2*depth(LCA).uandvcan be divided into 3 parts: the first part is in tree(u), the second part is on the cycle and the third part is in tree(v). In this case, the number of edges inside trees is simply depth(u)+depth(v).By Applying the above algorithm, we can solve the problem through O(n) time complexity preprocessing and then O(1) time complexity for each query. If there're
qqueries andqis quite large, this algorithm will show its advantage.