結果
問題 | No.1 道のショートカット |
ユーザー | ria_rai |
提出日時 | 2016-04-27 06:41:23 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 227 ms / 5,000 ms |
コード長 | 1,879 bytes |
コンパイル時間 | 2,331 ms |
コンパイル使用メモリ | 80,152 KB |
実行使用メモリ | 61,060 KB |
最終ジャッジ日時 | 2023-09-27 21:55:57 |
合計ジャッジ時間 | 10,724 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 115 ms
56,680 KB |
testcase_01 | AC | 113 ms
56,016 KB |
testcase_02 | AC | 116 ms
55,964 KB |
testcase_03 | AC | 121 ms
56,012 KB |
testcase_04 | AC | 110 ms
55,976 KB |
testcase_05 | AC | 113 ms
55,860 KB |
testcase_06 | AC | 116 ms
55,824 KB |
testcase_07 | AC | 126 ms
55,648 KB |
testcase_08 | AC | 186 ms
59,720 KB |
testcase_09 | AC | 189 ms
58,804 KB |
testcase_10 | AC | 193 ms
59,244 KB |
testcase_11 | AC | 196 ms
59,608 KB |
testcase_12 | AC | 192 ms
59,360 KB |
testcase_13 | AC | 207 ms
59,196 KB |
testcase_14 | AC | 150 ms
56,360 KB |
testcase_15 | AC | 111 ms
55,520 KB |
testcase_16 | AC | 167 ms
56,480 KB |
testcase_17 | AC | 115 ms
56,068 KB |
testcase_18 | AC | 163 ms
56,032 KB |
testcase_19 | AC | 156 ms
55,796 KB |
testcase_20 | AC | 168 ms
56,420 KB |
testcase_21 | AC | 160 ms
56,096 KB |
testcase_22 | AC | 156 ms
55,680 KB |
testcase_23 | AC | 227 ms
59,548 KB |
testcase_24 | AC | 193 ms
59,232 KB |
testcase_25 | AC | 174 ms
56,400 KB |
testcase_26 | AC | 163 ms
57,112 KB |
testcase_27 | AC | 201 ms
59,132 KB |
testcase_28 | AC | 118 ms
55,960 KB |
testcase_29 | AC | 200 ms
59,512 KB |
testcase_30 | AC | 173 ms
58,908 KB |
testcase_31 | AC | 172 ms
58,628 KB |
testcase_32 | AC | 188 ms
58,464 KB |
testcase_33 | AC | 185 ms
58,428 KB |
testcase_34 | AC | 197 ms
59,272 KB |
testcase_35 | AC | 188 ms
58,732 KB |
testcase_36 | AC | 189 ms
61,060 KB |
testcase_37 | AC | 183 ms
59,028 KB |
testcase_38 | AC | 140 ms
56,024 KB |
testcase_39 | AC | 169 ms
55,960 KB |
testcase_40 | AC | 177 ms
58,624 KB |
testcase_41 | AC | 157 ms
56,448 KB |
testcase_42 | AC | 113 ms
55,900 KB |
testcase_43 | AC | 113 ms
56,036 KB |
ソースコード
import java.util.*; public class Main { public static void main(String[] args) { // TODO Auto-generated method stub Scanner cin = new Scanner(System.in); int N = cin.nextInt(); int C = cin.nextInt(); int V = cin.nextInt(); ArrayList<List<Edge>> graph = new ArrayList<List<Edge>>(); for(int i = 0; i < N ; i++)graph.add(new ArrayList<Edge>()); int S[] = new int[V],T[] = new int[V] , Y[] = new int[V], M[] = new int[V]; int arr[][] = {S,T,Y,M}; for(int[] v:arr) for(int i = 0 ; i < V ; i++) v[i] = cin.nextInt(); for(int i = 0 ; i < V ; i++ ){ graph.get(S[i]-1).add(new Edge(T[i]-1,M[i],Y[i])); } System.out.println(Dijkstra(graph,0,N-1,C)); } public static class Edge implements Comparable{ int weight ; int dst; int money; Edge(int dst , int weight,int money){ this.weight = weight; this.dst = dst; this.money = money; } @Override public int compareTo(Object obj){ try{ Edge e = (Edge)obj ; if(this.weight > e.weight)return 1 ; else if(this.weight < e.weight)return -1; else return 0; }catch(ClassCastException e){ //ignore } return 0 ; } } static int Dijkstra(ArrayList<List<Edge>> graph, int src,int dst,int C){ PriorityQueue<Edge> qu = new PriorityQueue<Edge>(); int N = graph.size(); qu.add(new Edge(src,0,0)); int visited[][] = new int[N][C+1]; for(int[] v : visited)Arrays.fill(v, 1<<29); while(!qu.isEmpty()){ Edge e = qu.poll(); if(e.dst == dst) return (int)e.weight; if(e.weight > visited[e.dst][e.money])continue; visited[e.dst][e.money] = e.weight; List<Edge> nxt = graph.get(e.dst); for(Edge next :nxt){ if(next.money + e.money > C)continue; if(visited[next.dst][next.money+e.money] > next.weight + e.weight ){ qu.add(new Edge(next.dst,next.weight+e.weight,next.money+e.money)); } } } return -1; } }