We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 1d7cea8 commit a8ab996Copy full SHA for a8ab996
Graph/Topological-Sort.cpp
@@ -27,18 +27,19 @@ void topological_sort() {
27
reverse(ans.begin(), ans.end());
28
}
29
int main(){
30
+ cout << "Enter the number of vertices and the number of directed edges\n";
31
cin >> n >> m;
32
int x , y;
33
G.resize(n , vector<int>());
34
for(int i = 0 ; i < n ; ++i) {
35
cin >> x >> y;
- x-- , y--; //to convert 1-indexed to 0-indexed
36
+ x-- , y--; // to convert 1-indexed to 0-indexed
37
G[x].push_back(y);
38
39
topological_sort();
40
cout << "Topological Order : \n";
41
for(int v : ans) {
- cout << v << ' ';
42
+ cout << v + 1 << ' '; // converting zero based indexing back to one based.
43
44
cout << '\n';
45
return 0;
0 commit comments