You are not logged in. Please login at www.codechef.com to post your questions!

×

Can anyone suggest me how can i find longest chain of nodes ?

Can anyone suggest me how can i find longest chain of nodes in unweighted acyclic graph .It is also given that u can choose any node as a first node.

asked 14 Apr '15, 09:47

shubh_coder's gravatar image

1★shubh_coder
14
accept rate: 0%

edited 14 Apr '15, 09:48


If the graph is a DAG, then the first idea that would come into my head is a DP with memoization:

DP[v] -> the longest chain starting from vertex v.

Then DP[v] = 1+max{DP[w], w in Adj(v)}. You can easily compute this with memoization

Your answer is then max{DP[v]} for each vertex

If the graph is undirected, then it is a forest of trees, and this is a whole different problem (diameter of a tree)

link

answered 30 Jun '15, 01:54

retrograd's gravatar image

6★retrograd
1503
accept rate: 12%

edited 30 Jun '15, 01:55

toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×2,165
×1,655
×1,401
×366
×204
×141
×57

question asked: 14 Apr '15, 09:47

question was seen: 3,678 times

last updated: 30 Jun '15, 01:55