Describe
In the daily work of NetEase games, C + + is a common language. In the face of a lot of C + + code, waiting for the source file compilation long time is a dejected moment, everyone has been complaining about it. Finally, one day, we found you, a good programmer, ask you to help analyze the speed of the compilation bottleneck.
After some investigation and research, you find that there are dependencies between some source code. For example, a source file a.cpp a compilation link to a dynamic link library a.dll, and the b.dll generated by B.cpp compiled links is dependent on a.dll. At this point, you must wait for A.dll to generate B.dll. To express our simplicity, we call b.cpp dependent on a.cpp at this time.
NetEase game internal use of a distributed parallel compiler platform, you can compile multiple non-dependent files at the same time, greatly improving the source code compilation speed. However, when certain dependency chains are long, this build platform can do nothing but compile in the order of dependencies, resulting in a long compilation time.
To verify this idea, you decided to start by parsing the compilation sequence between these files. Given the file names of these files, as well as the other files that these files depend on, you need to write a program that outputs a workable compilation sequence of all the source files. If there are multiple possible sequences, output the smallest dictionary order in any file name sequence (sequence (,, ... a1 , a2 an ) The dictionary order is smaller than the sequence (,, ... b1 ,) b2 bn , when and only if there i is one, making ai The dictionary order is less than bi , and for any j < i , there is aj = bj ).
Input
The input contains multiple sets of test data.
The first line of input contains an integer T ( T ≤100), which indicates that the input contains a total of T group test data.
The first line of each set of test data is an integer N ( N ≤1000), which indicates that there is a N source code file altogether. Then there are N rows of data, where the i (0≤ i < N ) row data contains the i dependency information for the source code file with the ordinal number. Each line begins with a string representing the file name of the file, followed by an integer m (0≤ m ≤ N ), which indicates that a dependent file needs to be compiled before compiling the source file m . Then m there is an integer ... j0 jm-1 that represents the m ordinal of this dependent file (0≤ j < N ). All filenames are only lowercase letters, numbers, or "." and will not exceed 10 characters. Ensure that n the file names of the source code files are different.
Output
For each set of inputs, output a set of feasible compilation sequences in the Order of compilation, one per file name. If there are multiple possible sequences, output the one with the smallest dictionary order in the sequence of file names. If there is no feasible compilation order, output one line of ERROR. Output a blank line at the end of each set of test data.
Sample input
32a.cpp 0b.cpp 1 02CB 0c 02a.cpp 1 1b.cpp 1 0
Sample output
A.cppb.cppccberror
#include <iostream>#include<queue>#include<algorithm>#include<string>using namespacestd;BOOLCOM (pair<string,int>a, pair<string,int>b) {returnA.first <B.first;}intMain () {intT; while(Cin >>t) {vector<vector<string>>answer; while(t--) {vector<string>Answer1; intb CIN >> B; pair<string,int>file; vector<int>qianzhi; vector<vector<int>>houzhi (b); vector<pair<string,int>>File; for(inti =0; I! = b; ++i) {stringSintC CIN >> s >> C; File.first = s; File.second =i; File.push_back (file); Qianzhi.push_back (c); for(intj =0; J! = C; ++j) {intD CIN >>D; Houzhi[d].push_back (i); }} Queue<int>st; vector<pair<string,int>>repeat; for(inti =0; I! = b; ++i) {if(Qianzhi[i] = =0) Repeat.push_back (File[i]); } sort (Repeat.begin (), repeat.end (), COM); for(inti =0; I! = Repeat.size (); ++i) St.push (Repeat[i].second); intK =0; while(!St.empty ()) {repeat.clear (); intm =St.front (); Answer1.push_back (File[m].first); St.pop (); K++; for(inti =0; I! = Houzhi[m].size (); ++i) {--Qianzhi[houzhi[m][i]]; if(Qianzhi[houzhi[m][i]] = =0) {repeat.push_back (file[houzhi[m][i]);} } sort (Repeat.begin (), repeat.end (), COM); for(inti =0; I! = Repeat.size (); ++i) St.push (Repeat[i].second); } if(k = =b) {answer.push_back (answer1);} ElseAnswer.push_back (vector<string>{"ERROR"}); } for(inti =0; I! = Answer.size (); ++i) { for(intj =0; J! = Answer[i].size (); ++j) {cout<< Answer[i][j] <<Endl; } cout<<Endl; } }}
Internship Pen Test paper, source code compilation