Maximum Flow B#3641

Maximum Flow B

1 sekunt
128 megabaýt
Ýeňil

The bipartite graph, source and sink are given. Each disjoint set consists of vertices. The edges with capacities a_i run from the source to the vertices of the left set, from each vertex of the right set the edges of capacity b_i run to the sink. There are also edges of infinite capacity that run from the vertices of the left set to the vertices of the right set. The current can flow in both directions along these edges. Find the value of maximum flow from source to the sink.

Giriş

The numbers and (1 \le n \le 10^4, 0 \le k \le 10^5) are given - the number of vertices in each part of the graph and the number of edges between them. The second line contains the numbers a_i (1 \le a_i \le 10^4) - the edge capacities from source to each vertex in the left set. The third line contains the numbers b_i (1 \le b_i \le 10^4) - the edge capacities from each vertex of the right set to the sink. In each of the next lines two numbers and (1 \le u, v \le n) are given - the edge connects the vertex of the left set and the vertex of the right set.

Çykyş

Print the value of maximum flow.

Mysallar

1-nji mysal

Loading
Loading