that is a move called snaking. As they are swerving, they are pulling off mini-turbos, and getting ahead of you. Use the egg1 or the DB to snake. It takes some practice.
also: there is something called lag that I should mention here. IF they are going behind you and in front of you and "off the track, and put back on", you are a victim of lag. Information coming from their DS doesn't get to yours fast enough, and you see them fall off the track (an example) in reality, they didn't fall off, and while the DS was waiting for info, it continued them in a straight line. on their DS< you look the same way. This is not cheating, it just happens.