Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Minimum path cover in directed acyclic graph

The question I am going to ask here has already been asked before in stack overflow. But I am not able to understand properly the solutions posted by Skiminok.

Here is the Link .

I tried the solution posted on the above link with the given two sample test-cases ,but i am not able to get the correct answer.

For the test case 1::

N=3 and K=2

5 4 7

The DAG will be::

The directed acyclic graph for sample test case 1

Note :I have constructed the above DAG Considering:

Let pi and pj be two different problems. Then we will draw a directed edge from pi to pj if and only if pj can be solved directly after pi on the same day, consecutively. Namely, the following conditions have to be satisfied:

i < j, because you should solve the less difficult problem earlier.

|vi - vj| >= K (the rating requirement).

Then I constructed the Bipartite graph considering::

For each directed edge (u, v) of the original DAG one should add an undirected edge (au, bv) to the bipartite graph, where {ai} and {bi} are two parts of size n.

enter image description here

The answer =maximum cardinality matching in above bipartite graph .

maximum cardinality matching in above bipartite graph =1 (Green colored egde)

But the answer is 2.

Similarly Sample Test Case 2:

5 1

5 3 4 5 6

enter image description here

enter image description here

The MAx cardinality in above graph is MORE THAN ONE ,but the Correct answer is 1.

I think i am not implementing it correctly,please can you tell where i am making mistake Or is there any other Method

Thanks!

like image 835
Ritesh Kumar Gupta Avatar asked May 28 '12 10:05

Ritesh Kumar Gupta


People also ask

What is a minimum path cover?

A minimum path cover (MPC) of G is a path cover of G of minimum cardinality. If each edge e of G has a non-negative weight w(e), then a minimum weight minimum path cover is a minimum path cover MathML which minimizes the sum of the weights of the edges of the paths of MathML, that is, MathML Σ e∈P w(e).

What is the maximum number of edges in a directed acyclic graph?

The maximum number of edges in a DAG with n vertices is Θ(n2).

How many DAG paths are there?

So (since s and t must always be included) there are at most 2n−2 paths. This bound is tight, for a complete DAG (one in which every pair of vertices is connected by an edge, oriented consistently with a single topological order).

How do you find shortest path in directed acyclic graph explain with an example?

Given a Weighted Directed Acyclic Graph and a source vertex in the graph, find the shortest paths from given source to all other vertices. For a general weighted graph, we can calculate single source shortest distances in O(VE) time using Bellman–Ford Algorithm.


1 Answers

I found the answer myself , the next day i posted this question.

And my-solution passed all test cases .

I was making mistake in the last step. Actually the Answer/solution is the total Number of vertices in SET B that does not contain the edge of Maximal Bipartite Matching.

For Example on sample test case 1::

Maximal Matching M={(1A,3B)}.

No edge of maximal matching is incident upon two vertices (Vertex 1 and Vertex 2).So answer is equal to number of such vertex=2

For test case 2::

Maximal Matching M={(1A,2B),(2A,3B),(3A,4B),(4A,5B)}.

No edge of maximal matching is incident upon one vertex (Vertex 1).So answer is equal to 1

like image 153
Ritesh Kumar Gupta Avatar answered Oct 13 '22 21:10

Ritesh Kumar Gupta