結果
| 問題 |
No.1 道のショートカット
|
| コンテスト | |
| ユーザー |
_k_a_n_i_
|
| 提出日時 | 2015-01-29 18:37:06 |
| 言語 | Java (openjdk 23) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,692 bytes |
| コンパイル時間 | 3,606 ms |
| コンパイル使用メモリ | 79,316 KB |
| 実行使用メモリ | 56,228 KB |
| 最終ジャッジ日時 | 2024-07-08 03:42:02 |
| 合計ジャッジ時間 | 9,071 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 WA * 1 |
| other | AC * 16 WA * 24 |
ソースコード
import java.util.PriorityQueue;
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)
{
Data[] list = new Data[n];
for(int i=0; i<n; ++i)
{
list[i] = new Data(i, INF, INF);
}
list[0].cost = list[0].time = 0;
Queue<Data> queue = new PriorityQueue<Data>();
queue.add(list[0]);
while(!queue.isEmpty())
{
Data d = queue.poll();
int from = d.id;
for(int to=0; to<n; ++to)
{
if(map[from][to] != null && list[to].time > map[from][to].time + list[from].time && c >= map[from][to].cost + list[from].cost)
{
list[to].time = map[from][to].time + list[from].time;
list[to].cost = map[from][to].cost + list[from].cost;
queue.add(list[to]);
}
}
}
return list[g].time == INF ? -1 : list[g].time;
}
}
private class Data implements Comparable<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;
}
@Override
public int compareTo(Data o)
{
return time - o.time;
}
}
}
_k_a_n_i_