Please, try EDU on Codeforces! New educational section with videos, subtitles, texts, and problems.
×

# | User | Rating |
---|---|---|

1 | MiFaFaOvO | 3681 |

2 | tourist | 3669 |

3 | Um_nik | 3535 |

4 | 300iq | 3317 |

5 | ecnerwala | 3294 |

6 | maroonrk | 3268 |

7 | TLE | 3223 |

8 | scott_wu | 3209 |

9 | WZYYN | 3180 |

10 | boboniu | 3174 |

# | User | Contrib. |
---|---|---|

1 | Errichto | 197 |

2 | antontrygubO_o | 187 |

3 | pikmike | 182 |

3 | Ashishgup | 182 |

5 | vovuh | 179 |

6 | Radewoosh | 168 |

7 | Um_nik | 164 |

8 | tourist | 163 |

8 | Monogon | 163 |

10 | McDic | 162 |

↑

↓

Codeforces (c) Copyright 2010-2020 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Jul/08/2020 15:07:14 (f1).

Desktop version, switch to mobile version.

Supported by

User lists

Name |
---|

At first you can try to solve it by sqrt-decomposition:

1) Divide all queries to sqrt(max(n,m,k)) blocks.

2) In each block firstly add all edges that will be modified in block (denote it S) to mst in any order, and then try to add edges not from S one by one in non decreasing order to mst. If edge not from mst will be added then it should be in any mst in block, so you can merge the ends of that edge and make the number of vertexes equal to O(blockSize).

3) Now you should try to add edges not from S in non decreasing order to mst. Then each edge that will not be added to mst can't be in mst in block. So you can remove that edges and make number of edges equal to O(blockSize).

4) Finally you can simply build mst for each query in O(blockSize * alpha) time.

Okay. To get faster solution let's do the same in divide and conquer manner over queries: every time when we entering our

`solve`

function we should make the size of graph equal to the number of queries that we should process in function. So we have solution with complexity O(n * log^2n), cause we should sort the edges in block. Actually it's difficult to get complexity O(n logn) (I've not can) cause in paper authors telling us that we should firstly change all edges length by their numbers in sorted list of all lengths and then sort edges with integral lengths in O(numberOfEdges) time, but in that case we will get the constant about 16 or 32, cause the length of array will be different each time from (1 to n).Is it possible to solve this question online? Like for example, using a link-cut? Thanks.

[Edit]: I realised the link to the problem above isn't working so, here's a rough outline of the qn.

So u have a graph with some edges. Then there are some queries, after each query an edge weight changes, and u are supposed to output the cost of the current mst. (the change continues from that query onwards, (not just within that single query))

U can submit here but problem statement is in chinese (https://www.lydsy.com/JudgeOnline/problem.php?id=2001)

This problem is offline, and can be solved with the method mentioned above, but I'm just wondering if an online solution exists. :)

I think this is the problem from the blog post. https://codeforces.com/problemsets/acmsguru/problem/99999/529

Also, I can't read Chinese, but Google Translate leads me to believe that this blog talks about maintaining dynamic MST with LCT. https://www.cnblogs.com/flashhu/p/9498517.html

Could someone elaborate on the idea (if it is actually possible, of course).

If you start with a tree (as opposed to starting with no edges), then you when you are given an edge $$$e$$$ from $$$u$$$ to $$$v$$$ of cost $$$c$$$, you can find the maximum value edge on the path from $$$u$$$ to $$$v$$$ and if its value is greater than $$$c$$$, you can replace it with $$$e$$$, obtaining a tree with a smaller cost. All of these operations can be done with a LCT. Here is a possible implementation.

You are not given an edge, you are given edge weight updates.

It sounds like LCT can support dynamic MST with insertions but not deletions (or edge updates, since an update can be thought of as a deletion and an insertion).

There is an online solution that works in $$$O(m^{1/2})$$$ query time. This algorithm uses top trees. I don't know it, but I heard it have many applications in dynamic graph algorithms.

The best known bound is $$$O(\log^4 n)$$$ amortized per query. This would be impossible to phrase as a competitive programming task, but I think it's an interesting read?

* Poly-Logarithmic Deterministic Fully-Dynamic Algorithms for Connectivity, Minimum Spanning Tree, 2-Edge, and Biconnectivity