I doubt very much you even have the time. Ulvik is a tender port meaning that you are not in control of your own destiny as to what time you get ashore (likely to be ship's excursions first) and will have to be back at least an hour before the official departure time for last tenders.
It is 2 hours, give or take to Flam each way- it would have to be by private car at huge expense. There is public transport but no way will it work to that compressed schedule.
It is very unlikely you would have time either to do the railway or the Naeroyfjord cruise - the two big reasons to go to Flam. You certainly couldn't book either- it would be down to availability on the day.
I'm just scratching my head why you would go to Flam when you are on an arm of the Hardangerfjord- one of three of Norway's greatest fjords but not so well visited probably because it takes rather more effort to get there, than train to bus to train.
Are you aware that there is a Hardangerfjord in a Nutshell package (the same as Norway in a Nutshell)? - https://www.fjordtours.com/en/norway/tours/hardangerfjord-in-a-nutshell
It is normally done as a Bergen to Bergen day trip, but can be done from Voss to Voss.
But you should be able to get someone to put together the highlights of the H in a Nutshell as an Ulvik to Ulvik day excursion. That is what I would fully expect the ship to do, and is a classic case of taking a ship's excursion will clearly be the most efficient way to do it.