To understand this, you need to review and understand the differences between fetal circulation and post-natal (adult) circulation.
In the womb, very little of the cadiac output is directed to the fetal lungs because the lungs don't oxygenate the fetus's blood. Remember that the fetus's oxygen comes from the placenta, not its own lungs. The fetus lives in a relatively hypoxic environment, with a pO2 of approximately 35. This relative hypoxia is normal for the fetus (compared to a normal pO2 for an adult of 85) and causes the pulmonary blood vessels to constrict. This raises pulmonary blood pressure quite high, higher than the fetus's systemic blood pressure. So, with each heart beat, most of the cardiac output follows the path of least resistance and flows to the fetus's body. Very little flows to the fetal lungs, due to the relatively high pulmonary blood pressure. This works out just fine in utero where the fetus isn't responsible for oxygenating it's own blood, but not so well after delivery when the placenta is no longer available to provide oxygen.
At the moment of birth, when the baby takes it's first breath, the pO2 within the baby's bloodstream begins to rise, causing the pulmonary blood vessels to begin to relax, lowering pulmonary blood pressure. With subsequent breaths, the pO2 continues to rise, causing pulmonary vasodilation, which drops the pulmonary blood pressure lower than the systemic blood pressure (as it should be in adult circulation), and a greater portion of cardiac output begins to flow to the baby's lungs with each heartbeat, allowing the baby to sufficiently oxygenate its own blood.
If the baby is deprived of oxygen at birth, due to complications such as birth asphyxia, meconium aspiration or pneumonia, these changes may not occur, and the baby may develop a life-threatening condition called persistent pulmonary hypertension of the newborn (PPHN).
I've over-simplified my explanation a bit, because at the moment of birth, as the pO2 begins to rise, the fetal shunts begin to close (functionally), including the patent foramen ovale, the patent ductus arteriosus and the ductus venosus. This changes the pattern of blood flow thru the baby's heart and body to an adult pattern. If these shunts fail to close (functionally) at birth, or structurally within a few days-weeks of birth, then the baby may experience problems such as decreased oxygenation, murmur, CHF, poor feeding, poor weight gain, etc.