62 lines
1.7 KiB
C++
62 lines
1.7 KiB
C++
#pragma once
|
|
#include <vector>
|
|
#include <set>
|
|
#include <string>
|
|
#include <utility>
|
|
#include <tuple>
|
|
|
|
class Graph {
|
|
public:
|
|
Graph();
|
|
explicit Graph(int n);
|
|
Graph(int n, bool directed, bool weighted, char form);
|
|
|
|
int size() const { return n; }
|
|
bool isDirected() const { return directed; }
|
|
bool isWeighted() const { return weighted; }
|
|
char repr() const { return form; }
|
|
|
|
void readGraph(std::string fileName);
|
|
void writeGraph(std::string fileName);
|
|
|
|
void addEdge(int from, int to, int weight);
|
|
void removeEdge(int from, int to);
|
|
int changeEdge(int from, int to, int newWeight);
|
|
|
|
void transformToAdjList();
|
|
void transformToAdjMatrix();
|
|
void transformToListOfEdges();
|
|
|
|
Graph getSpaingTreePrima() const;
|
|
Graph getSpaingTreeKruscal() const;
|
|
Graph getSpaingTreeBoruvka() const;
|
|
|
|
int checkEuler(bool& circleExist) const;
|
|
std::vector<int> getEuleranTourFleri() const;
|
|
std::vector<int> getEuleranTourEffective() const;
|
|
|
|
int checkBipart(std::vector<char>& marks) const;
|
|
std::vector<std::pair<int, int>> getMaximumMatchingBipart() const;
|
|
|
|
Graph flowFordFulkerson(int source, int sink) const;
|
|
Graph flowDinitz(int source, int sink) const;
|
|
|
|
private:
|
|
int n = 0;
|
|
bool directed = false;
|
|
bool weighted = false;
|
|
char form = 'C';
|
|
|
|
std::vector<std::vector<int>> matrix;
|
|
std::vector<std::set<std::pair<int, int>>> adj;
|
|
std::vector<std::tuple<int, int, int>> edges;
|
|
|
|
bool hasEdge(int from, int to) const;
|
|
int weightOf(int from, int to) const;
|
|
|
|
std::vector<std::set<std::pair<int, int>>> toAdjList() const;
|
|
std::vector<std::vector<int>> toMatrix() const;
|
|
std::vector<std::tuple<int, int, int>> toEdgeList() const;
|
|
std::vector<std::set<int>> toSimpleAdj() const;
|
|
};
|