Submission details
Task:Ping
Sender:Anonyymit Algoritmistit
Submission time:2015-09-09 18:55:16 +0300
Language:Java
Status:COMPILE ERROR

Compiler report

input/Ping.java:10: error: package javafx.scene.layout does not exist
import javafx.scene.layout.Priority;
                          ^
Note: input/Ping.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
1 error

Code

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
//package kilo;

import java.util.ArrayList;
import java.util.PriorityQueue;
import javafx.scene.layout.Priority;

/**
 *
 * @author asjuvone
 */
public class Ping {
    
    public static int n;
    public static int q;
    public static int p;
    public static ArrayList<Kaari>[] verkko;

    public static void main(String[] args) {
        IO io = new IO();

        n = io.nextInt();
        q = io.nextInt();
        p = io.nextInt();

        verkko = new ArrayList[n + 1];
        verkko[0] = new ArrayList();

        for (int i = 1; i <= n; i++) {
            verkko[i] = new ArrayList();
        }

        for (int i = 1; i <= q; i++) {
            int a = io.nextInt();
            int b = io.nextInt();
            int paino = io.nextInt();

            verkko[a].add(new Kaari(i, paino, b));
            verkko[b].add(new Kaari(i, paino, a));

        }

//        for (int i=1; i<=n; i++) {
//            ArrayList<Kaari> kaaret = verkko[i];
//            for (int j = 0; j < kaaret.size(); j++) {
//                System.out.println("Kaaresta " + i + " pääsee " + kaaret.get(j));
//            }
//        }
        
       
        
        int alku = 1, loppu = q;
        
        while (alku < loppu) {
            int keski = (alku+loppu) / 2;
            long tulos = dijkstra(keski);
            if (tulos <= p) {
                loppu = keski;
            } else {
                alku = keski + 1;
            }
            //System.out.println("alku=" + alku);
        }
        //System.out.println("alku=" + alku + " pingi=" + dijkstra(alku));
        
              //  System.out.println("dijkstra at 4=" + dijkstra(4));
        if (dijkstra(alku) <= p) io.println(alku);
        else if (dijkstra(alku-1) <= p) io.println(alku-1);
        else io.println("QAQ");
        io.close();
        

    }
    
    public static long dijkstra(int aika) {
        PriorityQueue<Kaari> kaaret = new PriorityQueue<>();
        kaaret.add(new Kaari(1, 0, 1));
        
        boolean[] kayty = new boolean[n+1];
        while (!kaaret.isEmpty()) {
            Kaari nyk = kaaret.poll();
            if (kayty[nyk.kohde]) continue;
            kayty[nyk.kohde] = true;
            //System.out.println("kaytiin kohde " + nyk.kohde + " hetkella " + nyk.hetki);
            if (nyk.kohde == n) return nyk.paino;
            for (Kaari seur : verkko[nyk.kohde]) {
                 if (seur.hetki > aika) continue;
                 Kaari uusi = new Kaari(seur.hetki, nyk.paino + seur.paino, seur.kohde);
                 kaaret.add(uusi);
            }
        }
        return Long.MAX_VALUE;
    }

}

class Kaari implements Comparable<Kaari> {

    int kohde;
    int hetki;
    long paino;

    public Kaari(int hetki, long paino, int kohde) {
        this.kohde = kohde;
        this.hetki = hetki;
        this.paino = paino;
    }

    public String toString() {
        return "kohde: " + kohde;
    }

    @Override
    public int compareTo(Kaari o) {
        
        if (o.paino < this.paino) return 1;
        if (o.paino > this.paino) return -1;
        return 0;
    }

}