Undirected weighted graph. For every vertex you should find out shortest simple cycle, which includes this vertex.
I have only O(n ^ 4) solution. Can anybody help me?
# | User | Rating |
---|---|---|
1 | tourist | 3993 |
2 | jiangly | 3743 |
3 | orzdevinwang | 3707 |
4 | Radewoosh | 3627 |
5 | jqdai0815 | 3620 |
6 | Benq | 3564 |
7 | Kevin114514 | 3443 |
8 | ksun48 | 3434 |
9 | Rewinding | 3397 |
10 | Um_nik | 3396 |
# | User | Contrib. |
---|---|---|
1 | cry | 167 |
2 | Um_nik | 163 |
3 | maomao90 | 162 |
3 | atcoder_official | 162 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 156 |
8 | TheScrasse | 154 |
9 | Dominater069 | 153 |
10 | nor | 152 |
Undirected weighted graph. For every vertex you should find out shortest simple cycle, which includes this vertex.
I have only O(n ^ 4) solution. Can anybody help me?
Name |
---|
Auto comment: topic has been translated by Domonion (original revision, translated revision, compare)
are there negative edges?
seems like it's not. since it will make this problem NP-hard.
If O(n^3logn) is good enough, for each node, for each edge of the node, remove the edge, run dijkstras to find the distance from the node to the neighbor on the other side of the edge, and add the edge weight to it. The answer is the minimum of these.
Dijkstra's Algorithm does not run in O(N log(N)) time.
I think it's possible to do in . To compute answer for vertex v, run Dijkstra from it then for every edge w suposse that this edge is included in some cycle of v in the way (where wA and wB are vertexes connected by edge w) and calculate its weight. Answer for v gonna be a minimum of these weights.
It's also O(n^3 log n)
No it's not. For each vertex you run dijkstra and check all edges so actually it is O(n * (m + mlogn)). Of course if there will be like n2 edges then it indeed gonna work in O(n3 * logn), but if such constraints exists then n should be quite small.
Your algorithm does not always compute simple cycles. Consider the cycle , which is not a simple cycle, but is taken into account by your algorithm.
please ignore this :(
Won't work, the graph is undirected, so A[v][v] will be 2x the lightest outgoing edge from v.
omg i was stupid. Sorry for that
I don't know if this is a coincidence or not, but it seems you are not the only one solving this problem: http://research.haifa.ac.il/~raphy/papers/all-cycles.pdf