Lang:Java
Edit12345678910111213141516171819202122232425262728293031import java.io.*;import java.math.BigDecimal;import java.math.BigInteger;import java.math.RoundingMode;import java.util.*;public class Main {public static void main(String[] args) throws Exception {new Main().run();}static class Edge implements Comparable{int v;int w;int next;public Edge(int v,int w,int next){this.v = v;this.w = w;this.next = next;}@Overridepublic int compareTo(Object o) {Edge other = (Edge)o;if(this.w==other.w) return Integer.compare(this.v,other.v);else return Integer.compare(this.w,other.w);}}static int head[];static Edge edges[];static int count = 0;public static void addEdge(int u,int v, int w){