fix: clang-format for graph/ (#1056)

* fix: clang-format for graph/

* remove graph.h
This commit is contained in:
Filip Hlasek 2020-08-27 07:28:31 -07:00 committed by GitHub
parent 3239fcc19e
commit 79fb528dad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 67 additions and 60 deletions

View File

@ -89,11 +89,12 @@ void add_undirected_edge(std::vector<std::vector<int>> *graph, int u, int v) {
*
* @param graph Adjacency list representation of graph
* @param start vertex from where traversing starts
* @returns a binary vector indicating which vertices were visited during the search.
* @returns a binary vector indicating which vertices were visited during the
* search.
*
*/
std::vector<bool> breadth_first_search(const std::vector<std::vector<int>> &graph,
int start) {
std::vector<bool> breadth_first_search(
const std::vector<std::vector<int>> &graph, int start) {
/// vector to keep track of visited vertices
std::vector<bool> visited(graph.size(), false);
/// a queue that stores vertices that need to be further explored

View File

@ -27,14 +27,14 @@ class Solution {
bridge.push_back({itr, current_node});
}
}
out_time[current_node] = std::min(out_time[current_node], out_time[itr]);
out_time[current_node] =
std::min(out_time[current_node], out_time[itr]);
}
}
public:
std::vector<std::vector<int>> search_bridges(
int n,
const std::vector<std::vector<int>>& connections) {
int n, const std::vector<std::vector<int>>& connections) {
timer = 0;
graph.resize(n);
in_time.assign(n, 0);
@ -73,7 +73,8 @@ int main() {
* I assumed that the graph is bi-directional and connected.
*
*/
std::vector<std::vector<int>> bridges = s1.search_bridges(number_of_node, node);
std::vector<std::vector<int>> bridges =
s1.search_bridges(number_of_node, node);
std::cout << bridges.size() << " bridges found!\n";
for (auto& itr : bridges) {
std::cout << itr[0] << " --> " << itr[1] << '\n';

View File

@ -1,7 +1,7 @@
#include <iostream>
#include <list>
#include <vector>
#include <stack>
#include <vector>
constexpr int WHITE = 0;
constexpr int GREY = 1;

View File

@ -3,9 +3,8 @@
*/
#include <iostream>
#include <vector>
#include <stack>
#include <vector>
/**
* Iterative function/method to print graph:
@ -35,7 +34,8 @@ void print(const std::vector< std::vector<int> > &a, int V) {
* @param adj adjacency list representation of the graph
* @return void
**/
void push_vertex(int v, std::stack<int> *st, std::vector<bool> *vis, const std::vector< std::vector<int> > &adj) {
void push_vertex(int v, std::stack<int> *st, std::vector<bool> *vis,
const std::vector<std::vector<int> > &adj) {
(*vis)[v] = true;
for (auto i = adj[v].begin(); i != adj[v].end(); i++) {
if ((*vis)[*i] == false) {
@ -52,7 +52,8 @@ void push_vertex(int v, std::stack<int> *st, std::vector<bool> *vis, const std::
* @param grev graph with reversed edges
* @return void
**/
void dfs(int v, std::vector<bool> *vis, const std::vector< std::vector<int> > &grev) {
void dfs(int v, std::vector<bool> *vis,
const std::vector<std::vector<int> > &grev) {
(*vis)[v] = true;
// cout<<v<<" ";
for (auto i = grev[v].begin(); i != grev[v].end(); i++) {

View File

@ -1,7 +1,7 @@
#include <iostream>
#include <vector>
#include <algorithm>
#include <array>
#include <iostream>
#include <vector>
//#include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
const int mx = 1e6 + 5;

View File

@ -9,7 +9,8 @@
* Algorithm: https://cp-algorithms.com/graph/lca_binary_lifting.html
*
* Complexity:
* - Precomputation: \f$O(N \log N)\f$ where \f$N\f$ is the number of vertices in the tree
* - Precomputation: \f$O(N \log N)\f$ where \f$N\f$ is the number of vertices
* in the tree
* - Query: \f$O(\log N)\f$
* - Space: \f$O(N \log N)\f$
*
@ -34,11 +35,11 @@
* lowest_common_ancestor(x, y) = lowest_common_ancestor(y, x)
*/
#include <cassert>
#include <iostream>
#include <queue>
#include <utility>
#include <vector>
#include <queue>
#include <cassert>
/**
* \namespace graph
@ -70,16 +71,15 @@ class Graph {
* Function to get the number of vertices in the graph
* @return the number of vertices in the graph.
*/
int number_of_vertices() const {
return neighbors.size();
}
int number_of_vertices() const { return neighbors.size(); }
/** \brief for each vertex it stores a list indicies of its neighbors */
std::vector<std::vector<int> > neighbors;
};
/**
* Representation of a rooted tree. For every vertex its parent is precalculated.
* Representation of a rooted tree. For every vertex its parent is
* precalculated.
*/
class RootedTree : public Graph {
public:
@ -90,7 +90,8 @@ class RootedTree : public Graph {
* @param undirected_edges list of graph's undirected edges
* @param root_ index of the root vertex
*/
RootedTree(const std::vector< std::pair<int, int> > &undirected_edges, int root_)
RootedTree(const std::vector<std::pair<int, int> > &undirected_edges,
int root_)
: Graph(undirected_edges.size() + 1, undirected_edges), root(root_) {
populate_parents();
}
@ -135,7 +136,6 @@ class RootedTree : public Graph {
}
}
}
};
/**
@ -242,8 +242,7 @@ static void tests() {
* 9
*/
std::vector<std::pair<int, int> > edges = {
{7, 1}, {1, 5}, {1, 3}, {3, 6}, {6, 2}, {2, 9}, {6, 8}, {4, 3}, {0, 4}
};
{7, 1}, {1, 5}, {1, 3}, {3, 6}, {6, 2}, {2, 9}, {6, 8}, {4, 3}, {0, 4}};
graph::RootedTree t(edges, 3);
graph::LowestCommonAncestor lca(t);
assert(lca.lowest_common_ancestor(7, 4) == 3);

View File

@ -50,8 +50,10 @@ class Graph {
void set_graph() {
std::cin >> total_nodes >> total_edges >> source >> sink;
parent = std::vector<int>(total_nodes, -1);
capacity = residual_capacity = std::vector< std::vector<int> >(total_nodes, std::vector<int>(total_nodes));
for (int start = 0, destination = 0, capacity_ = 0, i = 0; i < total_edges; ++i) {
capacity = residual_capacity = std::vector<std::vector<int> >(
total_nodes, std::vector<int>(total_nodes));
for (int start = 0, destination = 0, capacity_ = 0, i = 0;
i < total_edges; ++i) {
std::cin >> start >> destination >> capacity_;
residual_capacity[start][destination] = capacity_;
capacity[start][destination] = capacity_;

View File

@ -2,7 +2,8 @@
#include <iostream>
#include <vector>
int number_of_vertices, number_of_edges; // For number of Vertices (V) and number of edges (E)
int number_of_vertices,
number_of_edges; // For number of Vertices (V) and number of edges (E)
std::vector<std::vector<int>> graph;
std::vector<bool> visited;
std::vector<int> topological_order;
@ -28,7 +29,8 @@ void topological_sort() {
reverse(topological_order.begin(), topological_order.end());
}
int main() {
std::cout << "Enter the number of vertices and the number of directed edges\n";
std::cout
<< "Enter the number of vertices and the number of directed edges\n";
std::cin >> number_of_vertices >> number_of_edges;
int x = 0, y = 0;
graph.resize(number_of_vertices, std::vector<int>());

View File

@ -32,7 +32,8 @@ int main() {
}
}
std::vector<int> topoSortKahn(int V, const std::vector< std::vector<int> > &adj) {
std::vector<int> topoSortKahn(int V,
const std::vector<std::vector<int> > &adj) {
std::vector<bool> vis(V + 1, false);
std::vector<int> deg(V + 1, 0);
for (int i = 0; i < V; i++) {