結果
| 問題 |
No.3013 ハチマキ買い星人
|
| ユーザー |
|
| 提出日時 | 2025-01-25 13:04:37 |
| 言語 | Java (openjdk 23) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 2,111 bytes |
| コンパイル時間 | 3,038 ms |
| コンパイル使用メモリ | 88,872 KB |
| 実行使用メモリ | 140,104 KB |
| 最終ジャッジ日時 | 2025-01-25 22:33:25 |
| 合計ジャッジ時間 | 80,891 ms |
|
ジャッジサーバーID (参考情報) |
judge8 / judge9 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 35 TLE * 10 |
ソースコード
import java.util.*;
public class Main {
public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int m = sc.nextInt();
int p = sc.nextInt();
long y = sc.nextLong();
Dijkstra djk = new Dijkstra(n);
long[] t = new long[n + 1];
for(int i = 1;i <= n;i++) {
t[i] = Long.MAX_VALUE;
}
for(int i = 0;i < m;i++) {
int a = sc.nextInt();
int b = sc.nextInt();
int c = sc.nextInt();
djk.addLine(a, b, c);
djk.addLine(b, a, c);
}for(int i = 0;i < p;i++) {
int d = sc.nextInt();
t[d] = sc.nextLong();
}
djk.solve(1,0);
long ans = 0;
for(int i = 1;i <= n;i++) {
long comp = Math.max(0, y - djk.min[i])/t[i];
ans = Math.max(ans, comp);
}System.out.print(ans);
}public static class Dijkstra {
public PriorityQueue<Pair> q = new PriorityQueue<>();
public long[] min;
public boolean[] vis;
public HashMap<Integer,HashSet<Pair>> nextNode = new HashMap<>();
public int n;
public Dijkstra(int n) {
this.n = n;
min = new long[n + 1];
vis = new boolean[n + 1];
for(int i = 1;i <= n;i++) {
min[i] = Long.MAX_VALUE/2;
nextNode.put(i, new HashSet<>());
}
}public void addLine(int from,int to,long cost) {
nextNode.get(from).add(new Pair(cost,to));
}
public void solve(int ind,long val) {
min[ind] = val;
q.add(new Pair(val,ind));
while(!q.isEmpty()) {
Pair p = q.poll();
if(vis[p.x])continue;
vis[p.x] = true;
for(Pair s:nextNode.get(p.x)) {
if(min[s.x] > min[p.x] + s.v) {
min[s.x] = min[p.x] + s.v;
q.add(new Pair(min[s.x],s.x));
}
}
}
}public long getMin(int a) {
return min[a];
}
public static class Pair implements Comparable<Pair> {
long v;
int x;
public Pair(long a,int b) {
v = a;
x = b;
}public int compareTo(Pair p) {
if(this.v < p.v) {
return -1;
}if(this.v > p.v) {
return 1;
}return 0;
}public boolean equals(Object o) {
Pair p = (Pair)o;
return p.x == this.x && p.v == this.v;
}
}
}
}