Code Submission Evaluation System Login

Datatähti 2016 alku

Start:2015-09-28 00:00:00
End:2015-10-12 00:00:00
 

Tasks | Scoreboard | Statistics


CSES - Datatähti 2016 alku - Results
History
2015-10-11 12:47:020
2015-10-11 11:55:480
2015-10-11 11:42:500
2015-10-10 23:01:330
2015-10-10 22:58:420
2015-10-10 22:58:410
2015-10-10 22:55:380
2015-10-10 22:46:420
2015-10-10 22:27:580
2015-10-10 22:22:050
2015-10-10 22:17:340
2015-10-07 11:12:020
2015-10-07 11:11:230
2015-10-07 10:56:040
2015-10-07 10:53:560
2015-10-07 10:45:300
2015-10-07 10:43:110
2015-10-07 10:35:510
2015-10-07 10:32:180
2015-10-07 10:17:210
2015-10-07 10:15:110
2015-10-07 00:39:500
2015-10-07 00:33:140
2015-10-07 00:32:350
2015-10-07 00:29:550
2015-10-07 00:28:310
2015-10-06 23:53:190
2015-10-06 23:47:540
2015-10-06 23:42:310
2015-10-06 23:40:040
2015-10-06 23:37:280
2015-10-06 23:35:21
Task:Lennot
Sender:Galax
Submission time:2015-10-06 23:35:21
Language:Java
Status:COMPILE ERROR

Compiler report

input/T4.java:5: error: class Main is public, should be declared in a file named Main.java
public class Main {
       ^
input/T4.java:9: error: cannot find symbol
        IO io = new IO();
        ^
  symbol:   class IO
  location: class Main
input/T4.java:9: error: cannot find symbol
        IO io = new IO();
                    ^
  symbol:   class IO
  location: class Main
3 errors

Code

package Main;

import java.util.*;

public class Main {
    
    public static void main(String[] args) {
        
        IO io = new IO();
        int cityAmount = io.nextInt();
        int flights = io.nextInt();
        
        ArrayList<City> cities = new ArrayList<>();
        
        for (int i = 1; i <= cityAmount; i++) {
            cities.add(new City(i));
        }
        for (int i = 0; i < flights; i++) {
            cities.get(io.nextInt()-1).neighbours.add(new Flight(cities.get(io.nextInt()-1),io.nextInt()));
        }
        flightCosts(cities.get(0));
        System.out.println(cities.get(cityAmount-1).minDistance);
    }
    
    public static void flightCosts(City source) {
        Boolean isFree = false;
        source.minDistance = 0;
        PriorityQueue<City> cityList = new PriorityQueue<City>();
	cityList.add(source);

	while (!cityList.isEmpty()) {
	    City c = cityList.poll();
            
            for (Flight flight : c.neighbours) {
                City v = flight.target;
                int cost = 0;
                if (!isFree) {
                    cost = flight.cost;
                }
                int newCost = c.minDistance + cost;
		if (newCost < v.minDistance) {
		    cityList.remove(v);
                    v.minDistance = newCost;
		    cityList.add(v);
		}
            }
            isFree = !isFree;
            
        }
    }

    
}
class City {
    public int name;
    public ArrayList<Flight> neighbours;
    public int minDistance = Integer.MAX_VALUE;
    public City(int name) {
        this.name = name; 
        neighbours = new ArrayList<>();
    }
    public int compareTo(City other) {
        return Integer.compare(minDistance, other.minDistance);
    }
}


class Flight {
    public City target;
    public int cost;
    public Flight(City target, int cost) { 
        this.target = target; 
        this.cost = cost; 
    }
}