I have a large graph and it is represented in adjacency list. I would like to compress the graph by merging the linear chain of nodes. For example, if the edges are a-c, b-c, c-d, d-e, e-f, e-g
:
a - c - d - e - f
| |
b g
Then c-d, d-e
can be merged to a single node x
and the new edge list should have a-x, b-x, x-g
. I would like to implement it in C++, but I am wondering if there is any C++ graph library which handles this. Also, any suggestion for a efficient algorithm is appreciated.