Go to diff to previous submission
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package fr; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.HashMap; /** * * @author cteam025 */ class Edge{ public Node n1; public Node n2; public int price; public Node dejSouseda(Node ja){ if(ja==n1){ return n2; } return n1; } } class Node{ public int id = 0; public Node parent; public int getEffort(Node parent, int parentPrice){ int price = 0; for(Edge h : hrany){ if(parent == h.dejSouseda(this)){ continue; } // System.out.println(h.dejSouseda(this).id); price += h.dejSouseda(this).getEffort(this, h.price); } if (parent == null){ return price; } if(price == 0 || price > parentPrice){ return parentPrice; } return price; } public Node(int id){ this.id = id; } } class Graph{ public Node root; public int nodes; public void addEdge(int f, int t, int price){ if(node1==null){ node1 = new Node(f); } if(node2==null){ node2 = new Node(t); } Edge hrana = new Edge(); hrana.price = price; hrana.n1 = node1; hrana.n2 = node2; node1.hrany.add(hrana); node2.hrany.add(hrana); } } public class Fr { /** * @param args the command line arguments */ // TODO code application logic here while(line != null){ Node root = new Node(rootId); Graph g = new Graph(); g.nodes = n; g.root = root; for(int i=0;i<(n-1);i++){ line = in.readLine(); g.addEdge(f,t,price); } line = in.readLine(); } } }
--- c5.s924.cteam025.fr.java.0.Fr.java +++ c5.s950.cteam025.fr.java.0.Fr.java @@ -51,7 +51,7 @@ } - int thisprice = parentPrice; - if(price == 0 || price > thisprice){ - return thisprice; + + if(price == 0 || price > parentPrice){ + return parentPrice; } @@ -108,23 +108,25 @@ String line = in.readLine(); - int n = Integer.parseInt(line.split(" ")[0]); - int rootId = Integer.parseInt(line.split(" ")[1]); - - Node root = new Node(rootId); - Graph g = new Graph(); - g.nodes = n; - g.root = root; - g.uzly.put(Integer.valueOf(rootId), root); - for(int i=0;i<(n-1);i++){ + while(line != null){ + int n = Integer.parseInt(line.split(" ")[0]); + int rootId = Integer.parseInt(line.split(" ")[1]); + + Node root = new Node(rootId); + Graph g = new Graph(); + g.nodes = n; + g.root = root; + g.uzly.put(Integer.valueOf(rootId), root); + for(int i=0;i<(n-1);i++){ + line = in.readLine(); + String params[] = line.split(" "); + int f = Integer.parseInt(params[0]); + int t = Integer.parseInt(params[1]); + int price = Integer.parseInt(params[2]); + g.addEdge(f,t,price); + } + + System.out.println(g.root.getEffort(null,0)); line = in.readLine(); - String params[] = line.split(" "); - int f = Integer.parseInt(params[0]); - int t = Integer.parseInt(params[1]); - int price = Integer.parseInt(params[2]); - g.addEdge(f,t,price); } - - System.out.println(g.root.getEffort(null,0)); - }