Source code for submission s987

Go to diff to previous submission

FQ.java

  1. /*
  2.  * To change this template, choose Tools | Templates
  3.  * and open the template in the editor.
  4.  */
  5. package fq;
  6.  
  7. import java.io.File;
  8. import java.io.FileNotFoundException;
  9. import java.util.Scanner;
  10.  
  11. /**
  12.  *
  13.  * @author drevenak3
  14.  */
  15. public class FQ {
  16.  
  17. /**
  18.   * @param args the command line arguments
  19.   */
  20. public static void main(String[] args) {
  21. Scanner scan = new Scanner(System.in);
  22. int n, u, v, hlavny;
  23. while (scan.hasNext()) {
  24. n = scan.nextInt();
  25. hlavny = scan.nextInt();
  26. int[][] pole = new int[n + 1][n + 1];
  27. for (int i = 1; i <= n-1; i++) {
  28. u = scan.nextInt();
  29. v = scan.nextInt();
  30. int c=scan.nextInt();
  31. pole[u][v] = c;
  32. pole[v][u] = c;
  33. }
  34. int e=0;
  35. for(int i=1;i<=n;++i){
  36. if(pole[hlavny][i]!=0){
  37. e+=enrgiaVetvy(pole,hlavny,i);
  38. }
  39. }
  40. System.out.println(e);
  41. }
  42. }
  43.  
  44. public static int enrgiaVetvy(int [][]paPole,int paZ,int paDo){
  45. int cestaPrisiel=paPole[paDo][paZ];
  46. int cestaZ=0;
  47. for(int i=1;i<paPole.length;++i){
  48. if(paPole[paDo][i]!=0&&i!=paZ){
  49. cestaZ+=enrgiaVetvy(paPole,paDo,i);
  50. }
  51. }
  52. if(cestaZ==0){
  53. return cestaPrisiel;
  54. }
  55. return Math.min(cestaPrisiel, cestaZ);
  56. }
  57. }
  58.  

Diff to submission s981

FQ.java

--- c5.s981.cteam083.fr.java.0.FQ.java
+++ c5.s987.cteam083.fr.java.0.FQ.java
@@ -7,5 +7,4 @@
 import java.io.File;
 import java.io.FileNotFoundException;
-import java.util.ArrayList;
 import java.util.Scanner;
 
@@ -21,7 +20,4 @@
     public static void main(String[] args) {
         Scanner scan = new Scanner(System.in);
-        try{
-            scan=new Scanner(new File("in.txt"));
-        }catch(FileNotFoundException e){}
         int n,  u, v,  hlavny;
         while (scan.hasNext()) {
@@ -36,20 +32,4 @@
                 pole[v][u] = c;
             }
-            /*ArrayList<Integer> rh=new ArrayList<Integer>();
-            ArrayList<Integer> rhw=new ArrayList<Integer>();
-            for(int i=1;i<=n;++i){
-                int st=0;
-                for(int j=1;j<i;++j){
-                    if(pole[i][j]!=0){
-                        ++st;
-                        if(st>=2) break;
-                    }
-                }
-                if(st==1){
-                    int min=0;
-                    
-                    rhw
-                }
-            }*/
             int e=0;
             for(int i=1;i<=n;++i){