結果

問題 No.1 道のショートカット
ユーザー GrenacheGrenache
提出日時 2016-03-04 23:02:33
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 2,146 bytes
コンパイル時間 3,882 ms
コンパイル使用メモリ 74,604 KB
実行使用メモリ 65,960 KB
最終ジャッジ日時 2023-09-22 12:38:44
合計ジャッジ時間 12,651 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 127 ms
56,076 KB
testcase_01 AC 125 ms
55,868 KB
testcase_02 AC 126 ms
55,716 KB
testcase_03 AC 132 ms
55,792 KB
testcase_04 AC 127 ms
55,492 KB
testcase_05 AC 126 ms
55,500 KB
testcase_06 AC 133 ms
55,780 KB
testcase_07 AC 139 ms
55,524 KB
testcase_08 AC 242 ms
60,452 KB
testcase_09 AC 207 ms
59,100 KB
testcase_10 AC 251 ms
60,992 KB
testcase_11 TLE -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Deque;
import java.util.List;
import java.util.Scanner;


public class Main_yukicoder1 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int c = sc.nextInt();
        int v = sc.nextInt();

        int[] s = new int[v];
        int[] t = new int[v];
        int[] y = new int[v];
        int[] m = new int[v];
        for (int i = 0; i < v; i++) {
        	s[i] = sc.nextInt();
        }
        for (int i = 0; i < v; i++) {
        	t[i] = sc.nextInt();
        }
        for (int i = 0; i < v; i++) {
        	y[i] = sc.nextInt();
        }
        for (int i = 0; i < v; i++) {
        	m[i] = sc.nextInt();
        }

        List<List<Triple>> edges = new ArrayList<List<Triple>>();
        for (int i = 0; i < n; i++) {
        	edges.add(new ArrayList<Triple>());
        }

        for (int i = 0; i < v; i++) {
        	edges.get(s[i] - 1).add(new Triple(t[i] - 1, y[i], m[i]));
        }

        Deque<Integer> st = new ArrayDeque<Integer>();
        Deque<Integer> cst = new ArrayDeque<Integer>();
        Deque<Integer> mst = new ArrayDeque<Integer>();
        st.push(0);
        cst.push(0);
        mst.push(0);

        int min = Integer.MAX_VALUE;
        while (!st.isEmpty()) {
        	int e = st.pop();
        	int ce = cst.pop();
        	int me = mst.pop();

        	if (e == n - 1) {
        		min = Math.min(min, me);
        		continue;
        	}

        	for (Triple next : edges.get(e)) {
        		int ne = next.a;
        		int nce = ce + next.b;
        		int nme = me + next.c;

        		if (nce <= c) {
        			st.push(ne);
        			cst.push(nce);
        			mst.push(nme);
        		}
        	}
        }

        if (min == Integer.MAX_VALUE) {
        	System.out.println(-1);
        } else {
        	System.out.println(min);
        }

        sc.close();
    }

    private static class Triple {
    	int a;
    	int b;
    	int c;

    	Triple(int a, int b, int c) {
    		this.a = a;
    		this.b = b;
    		this.c = c;
    	}
    }
}
0