結果
| 問題 |
No.1 道のショートカット
|
| コンテスト | |
| ユーザー |
_k_a_n_i_
|
| 提出日時 | 2015-01-29 18:48:25 |
| 言語 | Java (openjdk 23) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,409 bytes |
| コンパイル時間 | 2,119 ms |
| コンパイル使用メモリ | 79,436 KB |
| 実行使用メモリ | 56,284 KB |
| 最終ジャッジ日時 | 2024-07-08 03:42:47 |
| 合計ジャッジ時間 | 9,891 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 WA * 1 |
| other | AC * 16 WA * 24 |
ソースコード
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;
}
}
}
_k_a_n_i_