An algorithm for a decomposition of weighted digraphs: with applications to life cycle analysis in ecology