Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

kruskal java

import java.util.*;
import java.io.*;
public class Kruskal {
    static int p[];
    static int kruskal(int n, int m, Edge e[]) {
        int mst = 0, cnt = 0;
        for(int i =0; i < m; i++) {
            int u = e[i].u, v = e[i].v, w = e[i].w;
            if(cnt == n - 1) break;
            int fu = Find(u), fv = Find(v);
            if(fu != fv) { p[fu] = fv; cnt++; mst += w;}
        }
        return mst;
    }
    static int Find(int d) {
        if(d != p[d]) p[d] = Find(p[d]); return p[d];
    }
    static class Edge implements Comparable<Edge>{
        int u, v, w; public Edge(int u, int v, int w) {this.u = u; this.v = v; this.w = w;}
        public int compareTo(Edge x) { return Integer.compare(w,  x.w);}
    }
}
Comment

PREVIOUS NEXT
Code Example
Java :: how to highlight text in android studio 
Java :: Remove an element at a specific index from an array in Java 
Java :: replace all these caracters in string java 
Java :: and roid shape setCornerRadii 
Java :: Fix arabic javafx 
Java :: java method parameters 
Java :: Java Exceptions - Try...Catch 
Java :: array of arrays java 
Java :: merging two sorted arrays 
Java :: MyArrayList 
Java :: maximum integer in array java 
Java :: How to get the nth Fibonacci number code in Java using recursion with memoization 
Java :: overload and override in java 
Java :: org.apache.hadoop.mapred.JobClient.runJob(JobClient.java:876) 
Java :: type variable java 
Java :: java compare lists 
Java :: read many lines from stdn java 
Java :: convert jwt claim to string java 
Java :: How to make a Java Main Menu Loop after using a case 
Java :: how to generate random large string in java 
Java :: org.springframework.security.oauth2.jwt.JwtEncoder 
Java :: java sub function 
Java :: onclick listview javafx 
Java :: string to pojo java 
Java :: array copy java 
Java :: javadoc commands 
Java :: log messages not printing in springboot using org.slf4j.Logger; 
Java :: arrondi java 
Java :: get current location android 
Java :: flutter doctor Unable to find bundled Java version. 
ADD CONTENT
Topic
Content
Source link
Name
1+9 =