-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolution.java
More file actions
41 lines (30 loc) · 839 Bytes
/
Solution.java
File metadata and controls
41 lines (30 loc) · 839 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import java.util.*;
import java.io.*;
class Solution {
private static final String FILE_NAME = "input.txt";
public static void main (String[] args) {
try {
Scanner sc = new Scanner(new File(FILE_NAME));
int N_vertices = sc.nextInt();
int N_edges = sc.nextInt();
Edge[] edges = new Edge [N_edges];
for (int i = 0; i < N_edges; i++) {
int src = sc.nextInt();
int dst = sc.nextInt();
int weight = sc.nextInt();
Edge edge = new Edge(src, dst, weight);
edges[i] = edge;
}
Graph G = new Graph(edges, N_vertices);
Edge[] mst = G.MST_Kruskal();
int sum = 0;
for (Edge e : mst) {
System.out.println(e.toString());
sum += e.weight;
}
System.out.println("TOTAL MINIMUM WEIGHT: " + sum);
} catch (FileNotFoundException e) {
System.out.println(e.toString());
}
}
}