Safety evaluation and enhancement of urban rail transit network can identify risk bottlenecks and improve the network operation status, thereby reducing accidents and improving efficiency. Existing studies seldom consider quantitative calculation of operation risk and overall network distribution. In contrast, this paper proposes to quantitatively measure the safety of the rail transit network with a risk function. Minimizing the overall risk of the rail transit network is modeled as a convex optimization problem. Finally, a real case of Chongqing metro is taken for example to verify the method. The results show that with reasonable passenger flow assignment, the overall risk of the rail transit network is reduced.