Skip to content

Commit a8ab996

Browse files
authored
Update Topological-Sort.cpp
1 parent 1d7cea8 commit a8ab996

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

Graph/Topological-Sort.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,19 @@ void topological_sort() {
2727
reverse(ans.begin(), ans.end());
2828
}
2929
int main(){
30+
cout << "Enter the number of vertices and the number of directed edges\n";
3031
cin >> n >> m;
3132
int x , y;
3233
G.resize(n , vector<int>());
3334
for(int i = 0 ; i < n ; ++i) {
3435
cin >> x >> y;
35-
x-- , y--; //to convert 1-indexed to 0-indexed
36+
x-- , y--; // to convert 1-indexed to 0-indexed
3637
G[x].push_back(y);
3738
}
3839
topological_sort();
3940
cout << "Topological Order : \n";
4041
for(int v : ans) {
41-
cout << v << ' ';
42+
cout << v + 1 << ' '; // converting zero based indexing back to one based.
4243
}
4344
cout << '\n';
4445
return 0;

0 commit comments

Comments
 (0)