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

Function tsort

code/graph/tsort.cpp:13–24  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

11 color[cur] = 2;
12 res.push(cur); }
13vi tsort(int n, vvi adj, bool& cyc) {
14 cyc = false;
15 stack<int> S;
16 vi res;
17 char* color = new char[n];
18 memset(color, 0, n);
19 rep(i,0,n) {
20 if (!color[i]) {
21 tsort_dfs(i, color, adj, S, cyc);
22 if (cyc) return res; } }
23 while (!S.empty()) res.push_back(S.top()), S.pop();
24 return res; }
25// vim: cc=60 ts=2 sts=2 sw=2:

Callers 1

testFunction · 0.85

Calls 5

tsort_dfsFunction · 0.85
push_backMethod · 0.80
emptyMethod · 0.45
topMethod · 0.45
popMethod · 0.45

Tested by 1

testFunction · 0.68