public static int Kruskal(Graph input) {
		input.setState(States.ARR_ADJ);
		Log.print(Log.system, "Kruskal algorithm:");

		// init:
		int N = input.getVertexCount();
		int M = input.getEdgeCount();
		int[][] arr_inc = new int[N][M];
		int[][] arr_adj = new int[N][N];
		@SuppressWarnings("unchecked")
		ArrayList<ListNode>[] list_adj = new ArrayList[N];

		// init data:
		for (int i = 0; i < N; i++) {
			Arrays.fill(arr_adj[i], 0);
			Arrays.fill(arr_inc[i], 0);
			list_adj[i] = new ArrayList<ListNode>();
		}

		// Kruskal init:
		// For Krustal needed list of edges:
		DSF dsf = new DSF(input.getVertexCount());
		ArrayList<Edge> edges = input.getEdges();
		Collections.sort(edges);

		int cost = 0;
		for (Edge e : edges)
			if (dsf.union(e.u, e.v)) {
				System.out.println("Kruskal: edge " + (e.u + 1) + "-"
						+ (e.v + 1));
				cost += e.w;
			}
		return cost;
	}