There is a graph with N vertices and two types of queries:
1) connect U and V
2) disconnect U and V
After each query, the number of connected components should be printed. Is there a better solution than O(NQ)?
# | User | Rating |
---|---|---|
1 | ecnerwala | 3648 |
2 | Benq | 3580 |
3 | orzdevinwang | 3570 |
4 | cnnfls_csy | 3569 |
5 | Geothermal | 3568 |
6 | tourist | 3565 |
7 | maroonrk | 3530 |
8 | Radewoosh | 3520 |
9 | Um_nik | 3481 |
10 | jiangly | 3467 |
# | User | Contrib. |
---|---|---|
1 | maomao90 | 174 |
2 | adamant | 164 |
2 | awoo | 164 |
4 | TheScrasse | 160 |
5 | nor | 159 |
6 | maroonrk | 156 |
7 | -is-this-fft- | 150 |
7 | SecondThread | 150 |
9 | orz | 146 |
10 | pajenegod | 145 |
There is a graph with N vertices and two types of queries:
1) connect U and V
2) disconnect U and V
After each query, the number of connected components should be printed. Is there a better solution than O(NQ)?
Name |
---|
Auto comment: topic has been updated by Is1500EnoughForEGOI (previous revision, new revision, compare).
You can see it done here: https://cp-algorithms.com/data_structures/deleting_in_log_n.html in O(qlogn)
This is a dynamic connectivity problem. It was explained on Brazil's 2016 ICPC Summer School here.
Auto comment: topic has been updated by Is1500EnoughForEGOI (previous revision, new revision, compare).