Problem: https://codeforces.net/contest/1620/problem/E↵
↵
I was trying to apply some *dsu-like* logic in Problem E, when they asked for replacement of everyx$x$ with y$y$ in the array, but it gave me `WA on test 4`.↵
↵
The idea which I used during the contest:↵
↵
```↵
from = replacement[x], to = replacement[y]↵
while(replacement[to] != to) to = replacement[to];↵
replacement[from] = to;↵
```↵
↵
And, the idea which gave AC after the contest,↵
↵
```↵
replacement[x] = replacement[y]↵
```↵
↵
I know that the latter one is clever and more sleek, but why the former one fails? Can anyone please suggest a counter-case for it?↵
↵
Except for these idea, the rest of code was exact same!↵
↵
Submission 1 (with first logic): https://codeforces.net/contest/1620/submission/139872871 ↵
Submission 2 (with second logic): https://codeforces.net/contest/1620/submission/139872969
↵
I was trying to apply some *dsu-like* logic in Problem E, when they asked for replacement of every
↵
The idea which I used during the contest:↵
↵
```↵
from = replacement[x], to = replacement[y]↵
while(replacement[to] != to) to = replacement[to];↵
replacement[from] = to;↵
```↵
↵
And, the idea which gave AC after the contest,↵
↵
```↵
replacement[x] = replacement[y]↵
```↵
↵
I know that the latter one is clever and more sleek, but why the former one fails? Can anyone please suggest a counter-case for it?↵
↵
Except for these idea, the rest of code was exact same!↵
↵
Submission 1 (with first logic): https://codeforces.net/contest/1620/submission/139872871 ↵
Submission 2 (with second logic): https://codeforces.net/contest/1620/submission/139872969