In graph theory, a maximum spanning tree is a subgraph that is a tree and connects all the vertices with maximum weight sum. And a maximum spanning forest is the union of maximum spanning trees of each connected component in the graph.
A big undirected graph $G=(V,E)$ is given, which $V=\{(x,y) : 1 \le x,y \le 2,000,000,000;~x,y\in\mathbb{Z}\}$ and $E=\{\}$ initially. You're task is to write a program that support operation $x_1,y_1,x_2,y_2,c$:
First, add some edges in $G$. You should add an edge between $(a_1, b_1)$ and $(a_2, b_2)$ with weight $c$ if $x_1 \le a_1,a_2 \le x_2$, $y_1 \le b_1, b_2 \le y_2$ and $|a_1 - a_2| + |b_1 - b_2| = 1$.
Second, calculate the maximum spanning forest of $G$ after edges added.