library

This documentation is automatically generated by online-judge-tools/verification-helper

View the Project on GitHub kk2a/library

:heavy_check_mark: graph/edge.hpp

Depends on

Required by

Verified with

Code

#ifndef KK2_GRAPH_EDGE_HPP
#define KK2_GRAPH_EDGE_HPP 1

#include <type_traits>
#include <vector>

#include "../type_traits/io.hpp"

namespace kk2 {

namespace graph {

struct empty {};

template <class T> struct _Edge {
    int from, to, id;
    T cost;

    _Edge(int to_, T cost_, int from_ = -1, int id_ = -1)
        : from(from_),
          to(to_),
          id(id_),
          cost(cost_) {}
    _Edge() : from(-1), to(-1), id(-1) {}
    operator int() const { return to; }
    inline _Edge rev() const { return _Edge(from, cost, to, id); }

    template <class OStream, is_ostream_t<OStream> * = nullptr>
    void debug_output(OStream &os) const {
        os << '(' << id << ", " << from << "->" << to;
        if constexpr (!std::is_same_v<T, empty>) os << ":" << cost;
        os << ')';
    }
};

template <class T> struct _Edges : public std::vector<_Edge<T>> {
    using std::vector<_Edge<T>>::vector;

    template <class IStream, is_istream_t<IStream> * = nullptr>
    _Edges &input(IStream &is, bool is_one_indexed = false) {
        for (int i = 0; i < (int)this->size(); i++) {
            int u, v;
            T w{};
            is >> u >> v;
            if (is_one_indexed) --u, --v;
            if constexpr (!std::is_same_v<T, empty>) is >> w;
            (*this)[i] = _Edge<T>(v, w, u, i);
        }
        return *this;
    }

    template <class IStream, is_istream_t<IStream> * = nullptr>
    friend _Edges &input(_Edges &edges, IStream &is, bool is_one_indexed = false) {
        return edges.input(is, is_one_indexed);
    }

    template <class OStream, is_ostream_t<OStream> * = nullptr>
    void debug_output(OStream &os) const {
        os << '[';
        for (int i = 0; i < (int)this->size(); i++) {
            if (i) os << ", ";
            (*this)[i].debug_output(os);
        }
        os << ']';
    }

    _Edges &add_edge(int from, int to, T cost = T{}) {
        this->emplace_back(to, cost, from, this->size());
        return *this;
    }

    friend _Edges &add_edge(_Edges &edges, int from, int to, T cost = T{}) {
        edges.emplace_back(to, cost, from, edges.size());
        return edges;
    }
};

template <class T> struct _pair {
    T cost;
    int id;

    _pair(T cost_, int id_) : cost(cost_), id(id_) {}
    _pair() : cost(), id(-1) {}
    operator bool() const { return id != -1; }
    template <class OStream, is_ostream_t<OStream> * = nullptr>
    friend OStream &operator<<(OStream &os, const _pair &p) {
        if constexpr (std::is_same_v<T, empty>) return os;
        else return os << p.cost;
    }
};
template <class T> using _pairs = std::vector<_pair<T>>;

} // namespace graph

template <typename T> using WEdge = graph::_Edge<T>;
template <typename T> using WEdges = graph::_Edges<T>;
using Edge = graph::_Edge<graph::empty>;
using Edges = graph::_Edges<graph::empty>;

} // namespace kk2

#endif // KK2_GRAPH_EDGE_HPP
Traceback (most recent call last):
  File "/opt/hostedtoolcache/Python/3.12.0/x64/lib/python3.12/site-packages/onlinejudge_verify/documentation/build.py", line 71, in _render_source_code_stat
    bundled_code = language.bundle(stat.path, basedir=basedir, options={'include_paths': [basedir]}).decode()
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.12.0/x64/lib/python3.12/site-packages/onlinejudge_verify/languages/cplusplus.py", line 187, in bundle
    bundler.update(path)
  File "/opt/hostedtoolcache/Python/3.12.0/x64/lib/python3.12/site-packages/onlinejudge_verify/languages/cplusplus_bundle.py", line 401, in update
    self.update(self._resolve(pathlib.Path(included), included_from=path))
  File "/opt/hostedtoolcache/Python/3.12.0/x64/lib/python3.12/site-packages/onlinejudge_verify/languages/cplusplus_bundle.py", line 312, in update
    raise BundleErrorAt(path, i + 1, "#pragma once found in a non-first line")
onlinejudge_verify.languages.cplusplus_bundle.BundleErrorAt: type_traits/io.hpp: line 4: #pragma once found in a non-first line
Back to top page