Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8039857
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T03:42:46+00:00 2026-06-05T03:42:46+00:00

Suppose we are given a weighted graph G(V,E). The graph contains N vertices (

  • 0

Suppose we are given a weighted graph G(V,E).

The graph contains N vertices (Numbered from 0 to N-1) and M Bidirectional edges .

Each edge(vi,vj) has postive distance d (ie the distance between the two vertex vivj is d)

There is atmost one edge between any two vertex and also there is no self loop (ie.no edge connect a vertex to
itself.)

Also we are given S the source vertex and D the destination vertex.

let Q be the number of queries,each queries contains one edge e(x,y).

For each query,We have to find the shortest path from the source S to Destination D, assuming that edge (x,y) is absent in original graph.
If no any path exists from S to D ,then we have to print No.

Constraints are high 0<=(N,Q,M)<=25000

How to solve this problem efficiently?

Till now what i did is implemented the simple Dijakstra algorithm.

For each Query Q ,everytime i am assigning (x,y) to Infinity
and finding Dijakstra shortest path.

But this approach will be very slow as overall complexity will be Q(time complexity of Dijastra Shortes path)*

Example::

N=6,M=9
S=0 ,D=5

(u,v,cost(u,v))
0 2 4
3 5 8
3 4 1
2 3 1
0 1 1
4 5 1
2 4 5
1 2 1
1 3 3

Total Queries =6

Query edge=(0,1) Answer=7
Query edge=(0,2) Answer=5
Query edge=(1,3) Answer=5
Query edge=(2,3) Answer=6
Query edge=(4,5) Answer=11
Query edge=(3,4) Answer=8
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T03:42:48+00:00Added an answer on June 5, 2026 at 3:42 am

    First, compute the shortest path tree from source node to destination.

    Second, loop over all the queries and cut the shortest path at the edge specified by the query; this defines a min-cut problem, where you have the distance between the source node and the frontier of one partition and the frontier of the another and the destination; you can compute this problem very easily, at most O(|E|).

    Thus, this algorithm requires O(Q|E| + |V|log|V|), asymptotically faster than the naïve solution when |V|log|V| > |E|.

    This solution reuses Dijkstra’s computation, but still processes each query individually, so perhaps there are room to improvements by exploiting the work did in a previous query in successive queries by observing the shape of the cut induced by the edge.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have a weighted non-directed graph G = (V,E). Each vertex has a
Suppose in a given binary tree if each node contains number of child elements
Suppose I am given a weighted, connected graph. I'd like to find a list
Suppose we're given a colored graph. Let G be its automorphism group. How do
Suppose I am given number of lines segments in Cartesian coordinate system.Each line is
Suppose that you're given an array A of n distinct elements drawn from some
Suppose you have a dictionary that contains valid words. Given an input string with
I need to extract the dateformat from a given date. How am I suppose
Suppose you are given a Class.dll assembly compiled from the following simple code: namespace
Suppose you have a dictionary that contains valid words. Given an input string with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.