Skip to content

Commit

Permalink
more golf
Browse files Browse the repository at this point in the history
  • Loading branch information
lrvideckis committed Oct 23, 2024
1 parent d81bf6e commit 53a1582
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions content/graph/TopoSort.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@ vi topoSort(const vector<vi>& gr) {
vi indeg(sz(gr)), q;
for (auto& li : gr) for (int x : li) indeg[x]++;
rep(i,0,sz(gr)) if (indeg[i] == 0) q.push_back(i);
int j = 0;
while (j < sz(q)) {
int i = q[j++];
for (int x : gr[i])
if (--indeg[x] == 0) q.push_back(x);
}
rep(j,0,sz(q)) for (int x : gr[q[j]])
if (--indeg[x] == 0) q.push_back(x);
return q;
}

0 comments on commit 53a1582

Please sign in to comment.