I am solving this DIV 2C. This is my submission which got accepted.
My question is this:
Why isn't updating the parent of a node, an O(n) operation ?
№ | Пользователь | Рейтинг |
---|---|---|
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 |
Страны | Города | Организации | Всё → |
№ | Пользователь | Вклад |
---|---|---|
1 | cry | 167 |
2 | Um_nik | 163 |
3 | maomao90 | 162 |
3 | atcoder_official | 162 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 155 |
8 | TheScrasse | 154 |
9 | Dominater069 | 153 |
10 | nor | 152 |
I am solving this DIV 2C. This is my submission which got accepted.
My question is this:
Why isn't updating the parent of a node, an O(n) operation ?
Название |
---|
You are constructing the disjoint set using path compression. i.e. When you look for the father of a node, each node on the path to the root remember the father, so the complexity is not linear per query. If you want to be even more sure about the complexity you should do rank compression, i.e. remember for each tree their height, and make the shorter tree child of the taller tree (the one with highest height). The overall complexity per query is ackerman inverse per query (amortized).
More info about Disjoint Set.