Hãy xem xét vấn đề mà chúng ta được đưa ra làm đầu vào một đồ thị chu kỳ có hướng, a labeling function from to some set with a total order (e.g., the integers), and where we are asked to compute the lexicographically smallest topological sort of in terms of . More precisely, a topological sort of is an enumeration of as , such that for all , whenever there is a path from to in , then we must have . The label of such a topological sort is the sequence of elements of obtained as . The lexicographical order on such sequences (which all have length ) is defined as iff there is some position such that and for all . Pay attention to the fact that each label in can be assigned to multiple vertices in (otherwise the problem is trivial).
This problem can be stated either in a computation variant ("compute the lexicographically minimal topological sort") or in a decision variant ("is this input word the minimal topological sort?"). My question is, what is the complexity of this problem? Is it in PTIME (or in FP, for the computation variant) or is it NP-hard? If the general problem is NP-hard, I am also interested about the version where the set of possible labels is fixed in advance (i.e., there are only a constant number of possible labels).
Remarks:
Here is a small real-world example to motivate the problem. We can see the DAG as representing tasks of a project (with a dependency relationship between them) and the labels are integers representing the number of days that each task takes. To finish the project, it will take me the same total amount of time no matter the order I choose for the tasks. However, I would like to impress my boss, and to do this I want to finish as many tasks as possible as fast as possible (in a greedy manner, even if it means being very slow at the end because the harder tasks remain). Choosing the lexicographically minimal order optimises the following criterion: I want to choose an order such that there is no other order and a number of days where after days I would have finished more tasks with order than with order (i.e., if my boss looks at time , I give a better impression with ), but for all I have finished no less tasks with order than with order .
To give some insight about the problem: I already know from previous answers that the following related problem is hard: "is there a topological sort which achieves the following sequence"? However, the fact here that I want a sequence which is minimal for this lexicographic order seems to constrain a lot the possible topological orders that may achieve it (in particular the reductions in those other answers no longer seem to work). Intuitively, there are much less situations where we have a choice to make.
Note that there seems to be interesting rephrasings of the problems in terms of set cover (when restricting the problem to DAGs that are bipartite, i.e., have height two): given a set of sets, enumerate them in a order that minimises lexicographically the sequence , , , , . The problem can also be rephrased on undirected graphs (progressively expand a connected area of the graph following the order that minimizes the lexicographic sequence of the uncovered labels). However, because of the fact that the sequence has to be greedy at all times by definition of the lexicographic order, I can't get reductions (e.g., of Steiner tree) to work.
Thanks in advance for your ideas!