MCPcopy Create free account
hub / github.com/SuprDewd/CompetitiveProgramming / tsort_dfs

Function tsort_dfs

code/graph/tsort.cpp:1–12  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1void tsort_dfs(int cur, char* color, const vvi& adj,
2 stack<int>& res, bool& cyc) {
3 color[cur] = 1;
4 rep(i,0,size(adj[cur])) {
5 int nxt = adj[cur][i];
6 if (color[nxt] == 0)
7 tsort_dfs(nxt, color, adj, res, cyc);
8 else if (color[nxt] == 1)
9 cyc = true;
10 if (cyc) return; }
11 color[cur] = 2;
12 res.push(cur); }
13vi tsort(int n, vvi adj, bool& cyc) {
14 cyc = false;
15 stack<int> S;

Callers 1

tsortFunction · 0.85

Calls 1

pushMethod · 0.45

Tested by

no test coverage detected