-
Notifications
You must be signed in to change notification settings - Fork 20
/
mr.president.java
44 lines (41 loc) · 963 Bytes
/
mr.president.java
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
42
43
44
// https://www.hackerearth.com/practice/algorithms/graphs/minimum-spanning-tree/practice-problems/algorithm/mr-president/
/* package whatever; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
class Edge {
int u, v, w;
public Edge(int u, int v, int w) {
this.u = u;
this.v = v;
this.w = w;
}
}
class Ideone
{
static int[] parent;
static void union(int u, int v) {
int a = find(u);
int b = find(v);
if (a == b) return;
parent[a] = b;
}
static int find(int u) {
while (parent[u] != u) u = parent[u];
return u;
}
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
int n = sc.nextInt(); // vertices
int m = sc.nextInt(); // edges
Edges[] edges = new Edges[m+1];
for (int i = 0; i < m; i++) {
int a = sc.nextInt();
int b = sc.nextInt();
int w = sc.nextInt();
edges[i] = new Edge(a, b, w);
}
Collections.sort
}
}