結果

問題 No.1 道のショートカット
ユーザー _k_a_n_i__k_a_n_i_
提出日時 2015-01-29 18:48:25
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 2,409 bytes
コンパイル時間 4,349 ms
コンパイル使用メモリ 75,836 KB
実行使用メモリ 58,668 KB
最終ジャッジ日時 2023-09-22 11:53:46
合計ジャッジ時間 12,314 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 125 ms
55,588 KB
testcase_01 AC 127 ms
53,272 KB
testcase_02 AC 125 ms
55,696 KB
testcase_03 AC 124 ms
55,692 KB
testcase_04 WA -
testcase_05 AC 124 ms
55,632 KB
testcase_06 AC 122 ms
55,780 KB
testcase_07 AC 125 ms
55,824 KB
testcase_08 AC 169 ms
56,292 KB
testcase_09 AC 163 ms
56,368 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 124 ms
55,700 KB
testcase_16 WA -
testcase_17 AC 128 ms
55,944 KB
testcase_18 AC 132 ms
55,832 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 132 ms
55,736 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 137 ms
55,772 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 125 ms
55,652 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 157 ms
55,976 KB
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 AC 129 ms
55,728 KB
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 AC 125 ms
55,824 KB
testcase_43 AC 125 ms
55,540 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Arrays;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class Main
{
    private final static Main main = new Main();

    public static void main(String[] args)
    {
        long l = System.currentTimeMillis();
        main.answer();
        //System.out.println("処理時間:" + (System.currentTimeMillis() - l));
    }

    private void answer()
    {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int c = sc.nextInt();
        int v = sc.nextInt();
        sc.nextLine();
        String[] s = sc.nextLine().split(" ");
        String[] t = sc.nextLine().split(" ");
        String[] y = sc.nextLine().split(" ");
        String[] m = sc.nextLine().split(" ");
        sc.close();
        Data[][] map = new Data[n][n];
        for(int i=0; i<v; ++i)
        {
            int a = Integer.valueOf(s[i])-1;
            int b = Integer.valueOf(t[i])-1;
            int cost = Integer.valueOf(y[i]);
            int time = Integer.valueOf(m[i]);
            map[a][b] = new Data(i, cost, time);
        }
        System.out.println(new Dijkstra().dijkstra(map, c, n, n-1));
    }

    public class Dijkstra
    {
        private final int INF = Integer.MAX_VALUE/4;

        public int dijkstra(Data[][] map, int c, int n, int g)
        {
            int[] time = new int[n];
            Arrays.fill(time, INF);
            time[0] = 0;
            Queue<Data> queue = new LinkedList<Data>();
            queue.add(new Data(0, 0, 0));
            while(!queue.isEmpty())
            {
                Data d = queue.poll();
                int from = d.id;
                for(int to=0; to<n; ++to)
                {
                    if(map[from][to] != null && time[to] > time[from] + map[from][to].time && c >= d.cost + map[from][to].cost)
                    {
                        time[to] = time[from] + map[from][to].time;
                        queue.add(new Data(to, d.cost + map[from][to].cost, d.time));
                    }
                }
            }
            return time[g] == INF ? -1 : time[g];
        }
    }

    private class Data
    {
        private int id;
        private int cost;
        private int time;

        private Data(int id, int cost, int time)
        {
            this.id = id;
            this.cost = cost;
            this.time = time;
        }
    }
}
0