forked from xtaci/algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscc_demo.cpp
More file actions
45 lines (35 loc) · 683 Bytes
/
scc_demo.cpp
File metadata and controls
45 lines (35 loc) · 683 Bytes
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
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "directed_graph.h"
#include "graph_search.h"
#include "scc.h"
using namespace alg;
int main()
{
using namespace alg;
srand(time(NULL));
DirectedGraph * g = new DirectedGraph;
// construct 3 islands
int32_t i;
for (i=0;i<9;i++) {
g->add_vertex(i);
}
g->add_edge(0,1,1);
g->add_edge(1,2,1);
g->add_edge(2,0,1);
g->add_edge(3,4,1);
g->add_edge(4,5,1);
g->add_edge(5,3,1);
g->add_edge(6,7,1);
g->add_edge(7,8,1);
g->add_edge(8,6,1);
// connect island
g->add_edge(0,3,1);
g->add_edge(3,8,1);
g->printdot();
printf("find strongly connected component\n");
SCC(*g);
delete g;
return 0;
}