Image Example?Hey I was wondering If I have a graph that contains cycles. How can I break it into all possible Trees?? (Assuming the no. of vertices are very less?)
# | User | Rating |
---|---|---|
1 | tourist | 4009 |
2 | jiangly | 3823 |
3 | Benq | 3738 |
4 | Radewoosh | 3633 |
5 | jqdai0815 | 3620 |
6 | orzdevinwang | 3529 |
7 | ecnerwala | 3446 |
8 | Um_nik | 3396 |
9 | ksun48 | 3390 |
10 | gamegame | 3386 |
# | User | Contrib. |
---|---|---|
1 | cry | 167 |
2 | maomao90 | 163 |
2 | Um_nik | 163 |
4 | atcoder_official | 161 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 157 |
8 | TheScrasse | 154 |
9 | nor | 153 |
9 | Dominater069 | 153 |
Image Example?Hey I was wondering If I have a graph that contains cycles. How can I break it into all possible Trees?? (Assuming the no. of vertices are very less?)
Name |
---|
the simplest way is probably to just try all $$$n!$$$ paths, since in the worst case, there will be about $$$n!$$$ subtrees anyways.
However, if you want it to be fast, this is what i found: http://www.hariharan-ramesh.com/papers/spantree1.pdf and https://cs.ou.edu/~thulasi/Algorithm/Complexity%20of%20Computation%20of%20a%20Spanning%20Tree%20Enumeration%20Algorithm.pdf
to convert it to the tree you need to cancel cycles: to cancel a cycle you should at least delete one edge so you should make it independently for every cycle and then combine it, I think it needs very small constraints or a small number of cycles I see an idea like this Here
Maintain a visited array and add the edges as they're given in the input. If both nodes in a given edge are visited, discard the edge.