-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGraph.cpp
More file actions
57 lines (40 loc) · 1.09 KB
/
Graph.cpp
File metadata and controls
57 lines (40 loc) · 1.09 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<bool> vb;
enum{ UNVISITED = -1, VISITED = -2}; // Etiquetas básicas
vi dfs_num; /* No visitados
Si tu intención es utilizar la DFS en forma básica, puedes modificar el código y cambiar vi dfs_enum por
vb visited
AL = Adjacency List -> La estructura de datos más eficiente para el recorrido de grafos
AM = Adjacency Matrix
EL = Edges List
Puede resultar beneficioso empezar convirtiendo los grafos de entrada con forma AM o EL a AL antes de comenzar
el recorrido.
*/
void dfs(int u){
dfs_num[u] = VISITED;
for(auto& [v,w]: AL[u])
if (dfs_num[v] == UNVISITED)
dfs(v);
}
class Graph{
int V;
list <int> *l;
public:
Graph(int v){
V = v;
l = new list<int> [V];
}
void addEdge(int i,int j,bool undir = true){
l[i].push_back(j);
if(undir){
l[j].push_back(i);
}
}
};
// namespace std;
int main(){
Graph(6);
return 0;
}