diff --git a/graph/tarjan.cc b/graph/tarjan.cc index 8728649..84616b4 100644 --- a/graph/tarjan.cc +++ b/graph/tarjan.cc @@ -41,4 +41,23 @@ namespace tarjan { } return res; } -} \ No newline at end of file + vector>> build_scc_with_size(const vector>& ch) { + int n = ch.size(); + auto br = scc(ch); + int cnt = *max_element(br.begin(), br.end()); + vector> rb(cnt + 1); + for (int i = 0; i < n; ++i) { + for (auto&& u : ch[i]) { + rb[br[i]].emplace(br[u]); + } + } + vector>> res(cnt + 1); + for (int i = 1; i <= cnt; ++i) { + res[i].second = vector(rb[i].begin(), rb[i].end()); + } + for (int i = 1; i <= n; ++i) { + res[br[i]].first += 1; + } + return res; + } +}