import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.Comparator; import java.util.PriorityQueue; import java.util.StringTokenizer; class Main{ static final int INF=Integer.MAX_VALUE/2; static final PrintWriter out=new PrintWriter(System.out); static class Node{ int d; int v; Node(int d,int v){ this.d=d; this.v=v; } static final Comparator DISTANCE_ORDER=new DistanceOrderComparator(); public static class DistanceOrderComparator implements Comparator{ public int compare(Node n1,Node n2){ return (n1.d>n2.d)?1:(n1.d{} public static void main(String[] args) throws IOException{ BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String line=""; while((line=br.readLine())!=null&&!line.isEmpty()){ int n=Integer.parseInt(line); MyArrayList[] array=new MyArrayList[n]; int[] s=new int[n]; int[][] d=new int[n][n]; for(int i=0;i pque=new PriorityQueue(1,Node.DISTANCE_ORDER); Arrays.fill(d[s],INF); d[s][s]=0; pque.offer(new Node(0,s)); while(!pque.isEmpty()){ Node n=pque.poll(); int v=n.v; ArrayList list=array[v]; int dv=d[s][v]; int size=list.size(); if(dvdv+cost){ d[s][to]=dv+cost; pque.offer(new Node(d[s][to],to)); } } } } }