Khan’s algo :
using simple queue and sorting
while(!mq.empty()){
int v = mq.front();
mq.pop();
if(SZ(G[v]) == 0) continue;
for(int u : G[v]){
id[u]--;
if(id[u] == 0){
mq.push(u);
vp.pb(mp(u, r)); // push_back and make pair
}
}
++r;
}
Issue with the code is : node at same lvl are ranked with different numbers.
example
2 0
1 0
3 1
4 2
node 3 and 4 on same lvl but ranked diff.
i have tried priority queue, but ended with worse.