algorithm

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

View the Project on GitHub satashun/algorithm

:warning: cpp_src/graph/Visualize.hpp

Code

// label : index
// dot -Tsvg a.DOT -o a.svg

template <class T>
void to_graphviz(const Graph<T> g, string filename, bool directed = false) {
    ofstream ss(filename + ".DOT");
    if (directed) {
        ss << "digraph{\n";
        for (int i = 0; i < g.size(); ++i) {
            for (auto e : g[i]) {
                ss << i << "->" << e.to << "[label=\"index=" << e.idx
                   << ", cost=" << e.cost << "\"];\n";
            }
        }
    } else {
        ss << "graph{\n";
        for (int i = 0; i < g.size(); ++i) {
            for (auto e : g[i]) {
                if (e.to > i) {
                    ss << i << "--" << e.to << "[label=\"index=" << e.idx
                       << ", cost=" << e.cost << "\"];\n";
                }
            }
        }
    }

    ss << "}\n";
    ss.close();
    return;
}
#line 1 "cpp_src/graph/Visualize.hpp"
// label : index
// dot -Tsvg a.DOT -o a.svg

template <class T>
void to_graphviz(const Graph<T> g, string filename, bool directed = false) {
    ofstream ss(filename + ".DOT");
    if (directed) {
        ss << "digraph{\n";
        for (int i = 0; i < g.size(); ++i) {
            for (auto e : g[i]) {
                ss << i << "->" << e.to << "[label=\"index=" << e.idx
                   << ", cost=" << e.cost << "\"];\n";
            }
        }
    } else {
        ss << "graph{\n";
        for (int i = 0; i < g.size(); ++i) {
            for (auto e : g[i]) {
                if (e.to > i) {
                    ss << i << "--" << e.to << "[label=\"index=" << e.idx
                       << ", cost=" << e.cost << "\"];\n";
                }
            }
        }
    }

    ss << "}\n";
    ss.close();
    return;
}
Back to top page