結果
| 問題 |
No.3013 ハチマキ買い星人
|
| ユーザー |
tenten
|
| 提出日時 | 2025-01-28 09:14:40 |
| 言語 | Java (openjdk 23) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 2,625 bytes |
| コンパイル時間 | 2,385 ms |
| コンパイル使用メモリ | 82,132 KB |
| 実行使用メモリ | 53,500 KB |
| 最終ジャッジ日時 | 2025-01-28 09:14:52 |
| 合計ジャッジ時間 | 10,354 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 2 RE * 43 |
ソースコード
import java.io.*;
import java.util.*;
import java.util.function.*;
import java.util.stream.*;
public class Main {
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner();
int n = sc.nextInt();
int m = sc.nextInt();
int shop = sc.nextInt();
long y = sc.nextInt();
List<List<Path>> graph = new ArrayList<>();
for (int i = 0; i < n; i++) {
graph.add(new ArrayList<>());
}
for (int i = 0; i < m; i++) {
int a = sc.nextInt() - 1;
int b = sc.nextInt() - 1;
int c = sc.nextInt();
graph.get(a).add(new Path(b, c));
graph.get(b).add(new Path(a, c));
}
PriorityQueue<Path> queue = new PriorityQueue<>();
long[] costs = new long[n];
Arrays.fill(costs, Long.MAX_VALUE);
queue.add(new Path(0, 0));
while (queue.size() > 0) {
Path p = queue.poll();
if (costs[p.idx] <= p.value) {
continue;
}
costs[p.idx] = p.value;
for (Path x : graph.get(p.idx)) {
queue.add(new Path(x.idx, p.value + x.value));
}
}
long ans = 0;
while (shop-- > 0) {
int idx = sc.nextInt() - 1;
int price = sc.nextInt();
ans = Math.max(ans, Math.max(0, y - costs[idx]) / price);
}
System.out.println(ans);
}
static class Path implements Comparable<Path> {
int idx;
long value;
public Path(int idx, long value) {
this.idx = idx;
this.value = value;
}
public int compareTo(Path another) {
return Long.compare(value, another.value);
}
}
}
class Scanner {
BufferedReader br;
StringTokenizer st = new StringTokenizer("");
public Scanner() {
try {
br = new BufferedReader(new InputStreamReader(System.in));
} catch (Exception e) {
}
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
public String next() {
try {
while (!st.hasMoreTokens()) {
st = new StringTokenizer(br.readLine());
}
} catch (Exception e) {
e.printStackTrace();
} finally {
return st.nextToken();
}
}
}
tenten