algo

This documentation is automatically generated by competitive-verifier/competitive-verifier

View the Project on GitHub kuhaku-space/algo

:heavy_check_mark: なもりグラフ上のサイクル検出 (lib/graph/namori_graph.hpp)

Depends on

Verified with

Code

#pragma once
#include <stack>
#include <vector>
#include "graph/graph.hpp"

/// @brief なもりグラフ上のサイクル検出
template <class T>
std::vector<int> cycle_detection_on_namori_graph(const Graph<T> &g) {
    int n = g.size();
    std::vector<int> cnt(n);
    std::stack<int> st;
    for (int i = 0; i < n; ++i) {
        cnt[i] = g[i].size();
        if (cnt[i] == 1) st.emplace(i);
    }
    while (!st.empty()) {
        int x = st.top();
        st.pop();
        for (auto &e : g[x]) {
            if ((--cnt[e.to()]) == 1) st.emplace(e.to());
        }
    }

    std::vector<int> parent(n, -2);
    st = std::stack<int>();
    for (int i = 0; i < n; ++i) {
        if (cnt[i] >= 2) {
            parent[i] = -1;
            st.emplace(i);
        }
    }

    while (!st.empty()) {
        int x = st.top();
        st.pop();
        for (auto &e : g[x]) {
            if (parent[e.to()] == -2) {
                parent[e.to()] = x;
                st.emplace(e.to());
            }
        }
    }

    return parent;
}
Traceback (most recent call last):
  File "/home/runner/.local/lib/python3.12/site-packages/competitive_verifier/oj/resolver.py", line 291, in resolve
    bundled_code = language.bundle(path, basedir=basedir)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/runner/.local/lib/python3.12/site-packages/competitive_verifier/oj/verify/languages/cplusplus.py", line 242, in bundle
    bundler.update(path)
  File "/home/runner/.local/lib/python3.12/site-packages/competitive_verifier/oj/verify/languages/cplusplus_bundle.py", line 479, in update
    self._resolve(pathlib.Path(included), included_from=path)
  File "/home/runner/.local/lib/python3.12/site-packages/competitive_verifier/oj/verify/languages/cplusplus_bundle.py", line 286, in _resolve
    raise BundleErrorAt(path, -1, "no such header")
competitive_verifier.oj.verify.languages.cplusplus_bundle.BundleErrorAt: graph/graph.hpp: line -1: no such header
Back to top page