When you fly out of YVR for Alaska, you will pre-clear US customs at YVR, thereby arriving in Alaska as a 'domestic' flight. I would suggest you explain your itinerary to them (as previously mentioned the truth is always the best option).
Crossing the border on the train is another story. Never done that, sorry.
Of note, though. Some countries require an I94 waiver. I am not sure if this applies to you (green paper to be put in your passport) It costs $6 or $9. You must give it back to Canadian Customs when you leave the UK, even if it is valid for 90 days. When crossing at land borders, they will often ask you if you plan on returning to the US before it expires and leave it in the passport (to save you the money). Airport customs agents are far more strict against this policy and if you go through US customs at an airport in Canada with the green paper still in your passport you can get scolded. If you haven't turned it back before it expires (as proof you have left the US) the you can be in trouble.