Блог пользователя the.one.liner

Автор the.one.liner, история, 3 года назад, По-английски

How to solve WeirdSort problem via the tag "dfs and similar"?

  • Проголосовать: нравится
  • 0
  • Проголосовать: не нравится

»
3 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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://codeforces.com/contest/1311/submission/85116001