How to solve WeirdSort problem via the tag "dfs and similar"?
№ | Пользователь | Рейтинг |
---|---|---|
1 | jiangly | 3977 |
2 | tourist | 3815 |
3 | jqdai0815 | 3682 |
4 | ksun48 | 3614 |
5 | orzdevinwang | 3526 |
6 | ecnerwala | 3514 |
7 | Benq | 3483 |
8 | hos.lyric | 3381 |
9 | gamegame | 3374 |
10 | heuristica | 3358 |
Страны | Города | Организации | Всё → |
№ | Пользователь | Вклад |
---|---|---|
1 | cry | 169 |
2 | -is-this-fft- | 162 |
3 | Um_nik | 161 |
4 | atcoder_official | 159 |
5 | djm03178 | 157 |
6 | Dominater069 | 156 |
7 | adamant | 154 |
8 | luogu_official | 152 |
8 | awoo | 152 |
10 | TheScrasse | 148 |
How to solve WeirdSort problem via the tag "dfs and similar"?
Название |
---|
It is given that we are allowed to swap elements present at given index. Model the question as a graph having edges between these indexes and then find the connected components for all the indexes. Now, sort the array and see if the component of the index of the number that is present at index i in the sorted array is same as the component of index i itself.
My code using the above idea: https://mirror.codeforces.com/contest/1311/submission/85116001