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

  • Home
  • SEARCH
  • 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 6869053
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:30:37+00:00 2026-05-27T03:30:37+00:00

Given a directed graph G, with edges colored either green or purple, and a

  • 0

Given a directed graph G, with edges colored either green or purple, and a vertex S in G, I must find an algorithm that finds the shortest path from s to each vertex in G so the path includes at most two purple edges (and green as much as needed).

I thought of BFS on G after removing all the purple edges, and for every vertex that the shortest path is still infinity, do something to try to find it, but I’m kinda stuck, and it takes alot of the running time as well…

Any other suggestions?

Thanks in advance

  • 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-05-27T03:30:38+00:00Added an answer on May 27, 2026 at 3:30 am

    Duplicate your graph, so you have G1, G2, G3, such in each graph you redirect purple edges as follows: if (u1, v1) is a purple edge in G1, then change it to (u1, v2).

    I.e. You have three graphs where each time you take a purple edge it moves you to the next graph, and on G3 there are no more purple edges. That construction builds the purple restriction into the structure, and will then be enforced automatically.

    Now you simply find the shortest path from s to all nodes as usual. With the results you have to choose which is shorter between each path from s to u1, u2, u3.

    All in all the construction takes linear time, and the new graph size is O(1) times larger than the original, so APSP takes the same time, and the final run to determine which of the three paths found is shortest is also linear.

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

Sidebar

Related Questions

Given a directed graph with weighted edges, what algorithm can be used to give
Given a directed graph, I need to find the minimum set of vertices from
Given a weighted graph (directed or undirected) I need to find the cycle of
Given a table holding edges in a directed graph like this: CREATE TABLE edges
In a directed graph with non-negative edge weights I can easily find shortest path
Given a directed, connected graph with only positive edge weights, are there faster algorithms
Given a directed graph, the goal is to combine the node with the nodes
Given a parameter k , I'm trying to delete k edges from a directed
I'm writing an application that uses Dijkstra algorithm to find minimal paths in the
I have defined a C#-class, that shall be the elements of a directed graph

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.