Codeforces Round 1133 (Div. 1, Div. 2) is coming soon! Register here. ×

Toplogical Sort help needed
Difference between en1 and en2, changed 12 character(s)
Usually, topological sort is implemented like↵
↵
~~~~~↵
void dfs(int x) {↵
    vis[x] = true;↵
    for(int u = 0; u < n; u++) {↵
        if(!vis[u] && graph[x][u] == 1) {↵
            dfs(u);↵
        }↵
    }↵
    order.push_back(x);↵
}↵
~~~~~↵
↵
And then printed in reverse order↵
But if I implement this way↵
↵
~~~~~↵
void dfs(int x) {↵
    order.push_back(x);↵
    vis[x] = true;↵
    for(int u = 0; u < n; u++) {↵
        if(!vis[u] && graph[x][u] == 1) {↵
            dfs(u);↵
        }↵
    }↵
}↵
~~~~~↵
↵
And print in same order.↵
↵
Can someone provide me a test case where 2nd approach will fail

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en2 English anyon 2017-11-18 21:43:46 12
en1 English anyon 2017-11-18 20:48:36 619 Initial revision (published)