Actually I have to do topological ordering of the vertices of a graph. for this I have been provided with the code template given below.
#include <iostream>
#include <algorithm>
#include <vector>
using std::vector;
using std::pair;
void dfs(vector<vector<int> > &adj, vector<int> &used, vector<int> &order, int x) {
//write your code here
}
vector<int> toposort(vector<vector<int> > adj) {
vector<int> used(adj.size(), 0);
vector<int> order;
//write your code here
return order;
}
int main() {
size_t n, m;
std::cin >> n >> m;
vector<vector<int> > adj(n, vector<int>());
for (size_t i = 0; i < m; i++) {
int x, y;
std::cin >> x >> y;
adj[x - 1].push_back(y - 1);
}
vector<int> order = toposort(adj);
for (size_t i = 0; i < order.size(); i++) {
std::cout << order[i] + 1 << " ";
}
}
I am unable to understand the meaning of line " vector used(adj.size(), 0); ". Can anyone explain it please.