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 6231333
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T09:55:03+00:00 2026-05-24T09:55:03+00:00

I have a bunch of objects with level, weight and 0 or more connections

  • 0

I have a bunch of objects with level, weight and 0 or more connections to objects of the next levels. I want to know how do I get the “heaviest” path (with the biggest sum of weights).

I’d also love to know of course, what books teach me how to deal with graphs in a practical way.

  • 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-24T09:55:05+00:00Added an answer on May 24, 2026 at 9:55 am

    Your graph is acyclic right? (I presume so, since a node always points to a node on the next level). If your graph can have arbritrary cycles, the problem of finding the largest path becomes NP-complete and brute force search becomes the only solution.

    Back to the problem – you can solve this by finding, for each node, the heaviest path that leads up to it. Since you already have a topological sort of your DAG (the levels themselves) it is straighfoward to find the paths:

    1. For each node, store the cost of the heaviest path that leads to it and the last node before that on the said path. Initialy, this is always empty (but a sentinel value, like a negative number for the cost, might simplify code later)

    2. For nodes in the first level, you already know the cost of the heaviest path that ends in them – it is zero (and the parent node is None)

    3. For each level, propagate the path info to the next level – this is similar to a normal algo for shortest distance:

      for level in range(nlevels):
          for node in nodes[level]:
              cost = the cost to this node
               for (neighbour_vertex, edge_cost) in (the nodes edges):
                   alt_cost = cost + edge_cost
                   if  alt_cost < cost_to_that_vertex:
                       cost_to_that_vertex = alt_cost
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In C++, say you have a whole bunch of objects that you want to
So I have a bunch of objects (thumbnails) and I want every photo to
I have a bunch of objects that were serialized to XML. Now I want
Say I have a bunch of objects with dates and I regularly want to
I have a bunch of objects that have a value and a date field:
If I have a bunch of objects, and within these objects is the string
I'm working on a project where I have a bunch of objects (same type)
I have a bunch of different objects that are commonly edited in the same
I have a bunch of Thingy objects that I'm keeping track of using long
I currently have a bunch of SQLCHAR objects from a database query. The query

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.