zawatins-library

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

View the Project on GitHub zawa-tin/zawatins-library

:heavy_check_mark: Read-Graph (グラフ入力)
(src/graph/Read-Graph.hpp)

概要

std::vector<std::vector<int>> read_graph(int n, int m, bool undirect = true, bool minus = true)

グラフを隣接リスト表現で受け取ります

機能

Verified with

Code

#pragma once

#include <vector>
#include <iostream>

namespace zawa {

std::vector<std::vector<int>> read_graph(int n, int m, bool undirect = true, bool minus = true) {
    std::vector<std::vector<int>> res(n, std::vector(0, 0));
    for (int _ = 0 ; _ < m ; _++) {
        int u, v;
        std::cin >> u >> v;
        res[u - minus].emplace_back(v - minus);
        if (undirect) {
            res[v - minus].emplace_back(u - minus);
        }
    }
    return res;
}

std::vector<std::vector<int>> read_tree(int n, bool undirect = true, bool minus = true) {
    return read_graph(n, n - 1, undirect, minus);
}

}
#line 2 "src/graph/Read-Graph.hpp"

#include <vector>
#include <iostream>

namespace zawa {

std::vector<std::vector<int>> read_graph(int n, int m, bool undirect = true, bool minus = true) {
    std::vector<std::vector<int>> res(n, std::vector(0, 0));
    for (int _ = 0 ; _ < m ; _++) {
        int u, v;
        std::cin >> u >> v;
        res[u - minus].emplace_back(v - minus);
        if (undirect) {
            res[v - minus].emplace_back(u - minus);
        }
    }
    return res;
}

std::vector<std::vector<int>> read_tree(int n, bool undirect = true, bool minus = true) {
    return read_graph(n, n - 1, undirect, minus);
}

}
Back to top page