Question: Problem A Build Dependencies xkcd comic by Randall Munroe A Makefile is a file that specifies dependencies between different source code files. When one source

Problem A Build Dependencies

xkcd comic by Randall Munroe

A Makefile is a file that specifies dependencies between different source code files. When one source code file changes, this file needs to be recompiled, and when one or more dependencies of another file are recompiled, that file needs to be recompiled as well. Given the Makefile and a changed file, output the set of files that need to be recompiled, in an order that satisfies the dependencies (i.e., when a file XX and its dependency YY both need to be recompiled, YY should come before XX in the list).

Input

The input consists of:

  • one line with one integer nn (1n1000001n100000), the number of Makefile rules;

  • nn lines, each with a Makefile rule. Such a rule starts with ff: where ff is a filename, and is then followed by a list of the filenames of the dependencies of ff. Each file has at most 55 dependencies.

  • one line with one string cc, the filename of the changed file.

Filenames are strings consisting of between 11 and 1010 lowercase letters. Exactly nn different filenames appear in the input file, each appearing exactly once as ff in a Makefile rule. The rules are such that no two files depend (directly or indirectly) on each other.

Output

Output the set of files that need to be recompiled, in an order such that all dependencies are satisfied. If there are multiple valid answers you may output any of them.

Sample Input 1 Sample Output 1
6 gmp: solution: set map queue base: set: base gmp map: base gmp queue: base gmp 
gmp map set solution

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!