There are no trains between Edinburgh Waverley and Inverkeithing (so over the Forth Bridge) from 17 to 25 January to allow for track replacement and electrification.
[LNER and Scotrail trains north of Edinburgh to Aberdeen are diverting via Stirling and Perth with extended journey times]
Passengers for Fife (which includes St Andrews) are to use-Edinburgh Trams to Edinburgh Gateway for replacement buses to Inverkeithing where a limited train service to Fife will start.
For Dundee and stations forward to Aberdeen check whether the diverted trains or the tram/bus/train combo is the fastest option.
There is an easement for rail tickets to be valid on the trams.
The usual direct Stagecoach bus services will run from Edinburgh to Fife but rail tickets are NOT valid.
This is the full announcement- https://www.scotrail.co.uk/plan-your-journey/service-alterations/fife-electrification-and-track-re-railing-buses-replace