importjava.io.FileInputStream;importjava.util.*;publicclassMain{publicstaticvoidmain(String[]args)throwsException{// TODO Auto-generated method stubScannersc=newScanner(System.in);//Scanner sc = new Scanner(new FileInputStream("input.txt"));intcases=sc.nextInt();for(inti=0;i<cases;i++){intN=sc.nextInt();double[][]arr=newdouble[N][N];inttempN=sc.nextInt();for(intj=0;j<tempN;j++){inttemp1=sc.nextInt();inttemp2=sc.nextInt();doubletemp3=sc.nextDouble();arr[temp1][temp2]=temp3;}double[]distance=newdouble[N];distance[0]=1.0;for(intj=1;j<N;j++){distance[j]=999999999.9;}intcount=0;int[]check=newint[N];check[0]=1;intlevel=1;while(level!=N){doublemin=99999999.9;intindex=0;for(intj=0;j<N;j++){if(count==j||arr[count][j]==0)continue;if(distance[j]>distance[count]*arr[count][j])distance[j]=distance[count]*arr[count][j];if(check[j]!=1&&min>distance[j])index=j;}check[index]=1;count=index;level++;}System.out.printf("%.10f\n",distance[N-1]);}}}
chsalm
아무리 봐도 이유를 잘 모르겠습니다...ㅠㅠ
8년 전