The direct train from the outskirts of Cusco (Poroy station, service available from May to December) takes approximately 3 hours and a half to Machu Picchu Pueblo.
If you take the train at the Ollantaytambo station (two hours by road from Cusco), it will take you an hour and a half to get to Aguas Calientes.
If you make a single-day trip you may not enjoy your tour to the fullest. You must leave very early and return to Cusco at night.
Although you will be able to climb Huayna Picchu in the morning and do Circuit 1 in the afternoon, you will miss the opportunity to get to know the town of Aguas Calientes a bit, which has to offer, for example, the hot springs.
The best alternative would be to go from Cusco to Machu Picchu Pueblo in the morning, explore the surroundings, go to the hot springs, and sleep there. The next day, get up early to see Machu Picchu and return in the afternoon.
It all depends on the time of year. Keep in mind that the high season is from May to October (dry months) and the low season is from November to April (rainy months).
If you want to go to Machu Picchu, for example, in July and August, the most popular months, you will have to buy your tickets at least two months in advance.
If you go in the less touristy months, such as February or March, you can even buy from one day to the next.
If you go in high season, at any time of the day there will be a lot of people. However, most tourists prefer to go in the morning. Therefore, in the afternoon you will have more space and time to walk and take pictures.
If you want to climb Huayna Picchu, you can go very early to descend before noon, rest and enter Llaqta in the afternoon.