Let G and H be two weighted undirected simple graphs. We define the cartesian product of the two graphs, G□H, as the graph whose vertex set is the cartesian set product of the vertex sets of the two graphs V(G)×V(H) and in which there is an edge between vertices (u_1,v_1) and (u_2,v_2) if and only if:
You are given two connected graphs G and H. Compute the total weight of the minimum spanning tree of G□H.
The first line contains four integers n_1,m_1,n_2,m_2 (2≤n_1,n_2≤105; 1≤m_1,m_2≤105): the number of vertices of G, the number of edges of G, the number of vertices of H, and the number of edges of H, respectively.
Each of the next m_1 lines contains three integers u_i,v_i,w_i (0≤u_i,v_i≤n_1−1; 1≤w_i≤108), describing an edge of G between vertices u_i and v_i with weight w_i.
Each of the next m_2 lines contains three integers u_i,v_i,w_i (0≤u_i,v_i≤n_2−1; 1≤w_i≤108), describing an edge of H between vertices u_i and v_i with weight w_i.
It is guaranteed that graphs G and H are simple and connected. Recall that a graph is simple if there are no edges between a vertex and itself, and there is at most one edge between any two vertices.
Output one integer: the weight of the minimum spanning tree of G□H.