Submission details
Task:Ping
Sender:Anonyymit Algoritmistit
Submission time:2015-09-09 18:55:59 +0300
Language:Java
Status:READY
Result:ACCEPTED
Test results
testverdicttime
#1ACCEPTED0.17 sdetails
#2ACCEPTED0.17 sdetails
#3ACCEPTED1.38 sdetails
#4ACCEPTED0.55 sdetails
#5ACCEPTED0.78 sdetails
#6ACCEPTED0.65 sdetails
#7ACCEPTED1.07 sdetails
#8ACCEPTED0.73 sdetails
#9ACCEPTED0.96 sdetails
#10ACCEPTED0.73 sdetails
#11ACCEPTED0.43 sdetails
#12ACCEPTED0.77 sdetails
#13ACCEPTED0.63 sdetails
#14ACCEPTED0.74 sdetails
#15ACCEPTED1.12 sdetails
#16ACCEPTED0.80 sdetails
#17ACCEPTED0.77 sdetails

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;

/**
 *
 * @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;
    }

}

Test details

Test 1

Verdict: ACCEPTED

input
4 5 4
1 4 5
2 1 1
4 3 2
1 3 2
...

correct output
4

user output
4

Test 2

Verdict: ACCEPTED

input
4 3 4
1 3 2
3 4 3
2 4 1

correct output
QAQ

user output
QAQ

Test 3

Verdict: ACCEPTED

input
79228 100000 609719088
71059 11143 686695
68230 2527 877907
53438 29888 202308
3549 78720 356072
...

correct output
95914

user output
95914

Test 4

Verdict: ACCEPTED

input
54105 100000 146069808
21034 33530 208067
31369 39373 438341
53601 30432 458004
44664 29661 964679
...

correct output
47249

user output
47249

Test 5

Verdict: ACCEPTED

input
27534 100000 630452185
4554 20869 156656
18125 16857 129766
7327 23355 162783
12208 19586 330973
...

correct output
37629

user output
37629

Test 6

Verdict: ACCEPTED

input
100000 100000 1896201
37633 24342 686408
21326 35599 18816
68870 92002 748527
87772 68354 816268
...

correct output
QAQ

user output
QAQ

Test 7

Verdict: ACCEPTED

input
100000 100000 2753856
28301 86840 226813
23531 88963 140812
81527 28867 31169
81346 50536 187421
...

correct output
QAQ

user output
QAQ

Test 8

Verdict: ACCEPTED

input
100000 100000 8894369
96437 89061 279201
93127 41538 16340
5646 70264 970395
96240 15676 526054
...

correct output
89568

user output
89568

Test 9

Verdict: ACCEPTED

input
100000 100000 8920310
51576 49748 441411
75379 58501 720057
77269 34775 380776
45446 74022 804975
...

correct output
94792

user output
94792

Test 10

Verdict: ACCEPTED

input
5000 100000 699655
4460 4283 850197
3421 2128 903580
3335 401 848289
4975 4482 241023
...

correct output
58358

user output
58358

Test 11

Verdict: ACCEPTED

input
5000 100000 2906768
4100 2619 553305
4947 1462 263251
1703 4236 286383
4228 4797 635722
...

correct output
12392

user output
12392

Test 12

Verdict: ACCEPTED

input
5000 100000 8525016
4452 4625 772169
4941 929 373626
2610 379 935441
3007 4 402654
...

correct output
16113

user output
16113

Test 13

Verdict: ACCEPTED

input
5000 100000 6672172
2548 393 274388
1269 4076 230068
24 3024 596999
4658 2589 401693
...

correct output
3674

user output
3674

Test 14

Verdict: ACCEPTED

input
100000 100000 1000000000
61435 73156 809653003
31805 69457 997174565
46138 4746 664487503
77749 57316 726729812
...

correct output
QAQ

user output
QAQ

Test 15

Verdict: ACCEPTED

input
70000 100000 389981
69496 42899 329
42449 25317 445
2446 37175 175
4791 27488 51
...

correct output
71694

user output
71694

Test 16

Verdict: ACCEPTED

input
70000 100000 7413515
66481 13331 14
34935 8021 953
66946 55602 904
49080 1580 157
...

correct output
82046

user output
82046

Test 17

Verdict: ACCEPTED

input
20000 100000 100000000
1 2 10000
2 3 10000
3 4 10000
4 5 10000
...

correct output
50001

user output
50001