i want to do topo sort but i want to output the lexographically smallest topo sort vesion of that. http://www.spoj.com/problems/TOPOSORT/ here goes the link of problem. actually, i have done this using DFS , but i am able to do the question "print any possible topo sort" of the graph. thanks if u can help me.
void dfs(int p)
{
if(used[p]==1)
{
flag=false;
return;
}
else if(used[p]==0)
{
used[p]=1;
for(int i=0;i<g[p].size();i++)
{
dfs(g[p][i]);
}
used[p]=2;
ans.push_back(p);
}
else
return;
}
here ans vector is the answer in which topo sort is there. thanks if u can help me .