Update Topological-Sort.cpp

This commit is contained in:
Abhishek Yadav 2019-02-20 00:15:38 +05:30 committed by GitHub
parent 1d7cea86ec
commit a8ab996d27
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -27,18 +27,19 @@ void topological_sort() {
reverse(ans.begin(), ans.end());
}
int main(){
cout << "Enter the number of vertices and the number of directed edges\n";
cin >> n >> m;
int x , y;
G.resize(n , vector<int>());
for(int i = 0 ; i < n ; ++i) {
cin >> x >> y;
x-- , y--; //to convert 1-indexed to 0-indexed
x-- , y--; // to convert 1-indexed to 0-indexed
G[x].push_back(y);
}
topological_sort();
cout << "Topological Order : \n";
for(int v : ans) {
cout << v << ' ';
cout << v + 1 << ' '; // converting zero based indexing back to one based.
}
cout << '\n';
return 0;