Pagini recente » Cod sursa (job #1113472) | Cod sursa (job #1635322) | Cod sursa (job #2280016) | Cod sursa (job #1902296) | Cod sursa (job #2156582)
#include<fstream>
#include<list>
using namespace std;
ifstream fin("sortaret.in");
ofstream fout("sortaret.out");
const int NMAX = 5e4 + 5;
list<int> adjList[NMAX];
int Stack[NMAX];
int nodesCnt, edgesCnt, StackLen;
inline void readData(){
fin >> nodesCnt >> edgesCnt;
int from, to;
while(edgesCnt--){
fin >> from >> to;
adjList[from].push_back(to);
}
}
void topoSort(int node){
for(const auto &nextNode : adjList[node])
topoSort(nextNode);
Stack[++StackLen] = node;
}
inline void print(){
while(StackLen){
fout << Stack[StackLen] << ' ';
--StackLen;
}
}
int main(){
readData();
topoSort(1);
print();
}