-
Notifications
You must be signed in to change notification settings - Fork 0
/
MST.h
41 lines (27 loc) · 770 Bytes
/
MST.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#ifndef MST_H
#define MST_H
#include <iostream>
#include <vector>
using namespace std;
class UnionFind{
private:
vector<int> par, size;
public:
UnionFind(int n);
int find(int a);
void unite(int a, int b);
bool isSame(int a, int b);
};
struct Edge{
int u; // first vertice
int v; // second vertice
int c; // weight
Edge(int n_u, int n_v, int n_c);
bool operator<(const Edge& edge) const;
friend ostream& operator<<(ostream& os, const Edge& edge);
};
vector<Edge> build_MST(vector<Edge> &EdgeList, int n);
void build_MST(vector<pair<int,int>> *adjList, vector<Edge> &EdgeList, int n);
void print(vector<Edge> tree);
vector<vector<pair<int,int>>> to_adj_list(vector<Edge> &edge_list, int n);
#endif