-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathmain_CC.cpp.in
42 lines (38 loc) · 894 Bytes
/
main_CC.cpp.in
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
/******************************************************************************
* % ./CC tinyG.txt
* 3 components
* 6 5 4 3 2 1 0
* 8 7
* 12 11 10 9
*
* % ./KosarajuSCC tinyDG.txt
* 5 components
* 1
* 5 4 3 2 0
* 12 11 10 9
* 8 6
* 7
*
******************************************************************************/
#include <fstream>
#include <iostream>
#include <list>
#include "@[email protected]"
int main(int argc, char *argv[]) {
std::ifstream in(argv[1]);
#ifndef DIRECTED
Graph G(in);
#else
Digraph G(in);
#endif
@CC@ cc{G};
int M = cc.count();
std::cout << M << " components" << std::endl;
std::list<int> components[M];
for (int v = 0; v < G.V(); ++v) components[cc.id(v)].push_front(v);
for (int i = 0; i < M; ++i) {
for (int v: components[i]) std::cout << v << " ";
std::cout << std::endl;
}
return 0;
}