#P5687. Minimum Spanning Tree on a Grid Graph
Minimum Spanning Tree on a Grid Graph
Minimum Spanning Tree on a Grid Graph
Given a grid graph of size with rows numbered from to and columns numbered from to . Each vertex is denoted by its coordinates . There is an edge between and with weight for and , and an edge between and with weight for and . Your task is to compute the total weight of the minimum spanning tree (MST) for this graph.
inputFormat
The input consists of three lines. The first line contains two integers and . The second line contains integers . The third line contains integers .
outputFormat
Output a single integer representing the total weight of the minimum spanning tree.
sample
2 3
1 3
2 1 4
8