가중 이분 그래프를 k개 이어 붙인 층상 네트워크에서 최대 유량이 수렴하는지 판정하고, 수렴하면 그 극한값을, 아니면 -1을 출력한다.
어려움9그래프최단 경로최소 신장 트리아직 제출이 없습니다시간 제한2초메모리 제한256 MBWe are considering a maximum flow problem on an infinite network.
You are given a bipartite graph G with n vertices in both parts and m directed edges. Each edge goes from the left part to the right part, and has its capacity specified. We want to construct a family of networks F_k.
Here are the steps to construct the network F_k.
Let f_k be the maximum flow in the network F_k.
We want to know what the sequence f_k looks like when k goes to infinity. If f_k does not converge to a constant, output −1. Otherwise, output lim_k→+∞f_k.
The first line contains two integers n and m (1≤n≤2000, 1≤m≤4000).
Each of the following m lines contains three integers u, v, and w (1≤u,v≤n, 1≤w≤105) which indicate that there is a directed edge from the u-th vertex in the left part to the v-th vertex in the right part with capacity w.
If the sequence f_k does not converge to a constant, output −1. Otherwise, output lim_k→+∞f_k.